473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Programming a simple firewall in C#

I'm working on a programming project that needs to control network traffic.
What I would like to do implement a mini-firewall as part of my program.
What would be involved with writing a firewall like program in C#? I realize
it's not really a simple project, but the firewall doesn't have to be very
smart. Just block data to all hosts except a few specific hosts/ports. Any
suggestions on how I should proceed would be greatly appreciated!
Nov 16 '05 #1
4 23297
Paul:

Are you trying to control the traffic to and or from just your
application, or the entire machine?

If for the entire machine, your best bet might be to look at the
Routing and Remote Access Service APIs in the Platform SDK. You'll
have to PInvoke functions like PfCreateInterface,
PfAddFiltersToInterface, and so on:

http://msdn.microsoft.com/library/de..._reference.asp

I'm sure you could get some help if you google for some of the API
names.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Thu, 21 Oct 2004 17:38:17 -0300, "Paul Steele"
<pa*********@acadiau.ca> wrote:
I'm working on a programming project that needs to control network traffic.
What I would like to do implement a mini-firewall as part of my program.
What would be involved with writing a firewall like program in C#? I realize
it's not really a simple project, but the firewall doesn't have to be very
smart. Just block data to all hosts except a few specific hosts/ports. Any
suggestions on how I should proceed would be greatly appreciated!


Nov 16 '05 #2
Thanks for the information. My primary goal is to control outgoing traffic
for the entire machine. Incoming isn't as important but probably will need
some control as well. I'll check out your references and see what I can
find.

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:n7********************************@4ax.com...
Paul:

Are you trying to control the traffic to and or from just your
application, or the entire machine?

If for the entire machine, your best bet might be to look at the
Routing and Remote Access Service APIs in the Platform SDK. You'll
have to PInvoke functions like PfCreateInterface,
PfAddFiltersToInterface, and so on:

http://msdn.microsoft.com/library/de..._reference.asp

I'm sure you could get some help if you google for some of the API
names.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Thu, 21 Oct 2004 17:38:17 -0300, "Paul Steele"
<pa*********@acadiau.ca> wrote:
I'm working on a programming project that needs to control network
traffic.
What I would like to do implement a mini-firewall as part of my program.
What would be involved with writing a firewall like program in C#? I
realize
it's not really a simple project, but the firewall doesn't have to be very
smart. Just block data to all hosts except a few specific hosts/ports. Any
suggestions on how I should proceed would be greatly appreciated!

Nov 16 '05 #3
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:n7********************************@4ax.com...
Paul:

Are you trying to control the traffic to and or from just your
application, or the entire machine?

If for the entire machine, your best bet might be to look at the
Routing and Remote Access Service APIs in the Platform SDK. You'll
have to PInvoke functions like PfCreateInterface,
PfAddFiltersToInterface, and so on:

http://msdn.microsoft.com/library/de..._reference.asp

I'm sure you could get some help if you google for some of the API
names.


I found this solution at Code Project. It appears to be exactly what I want:

http://www.thecodeproject.com/manage...lteringnet.asp
Nov 16 '05 #4
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:n7********************************@4ax.com...
Paul:

Are you trying to control the traffic to and or from just your
application, or the entire machine?

If for the entire machine, your best bet might be to look at the
Routing and Remote Access Service APIs in the Platform SDK. You'll
have to PInvoke functions like PfCreateInterface,
PfAddFiltersToInterface, and so on:

http://msdn.microsoft.com/library/de..._reference.asp

I'm sure you could get some help if you google for some of the API names.


I've found the information on the various packet filtering functions and
they seem relatively straightforward to use. However, I'm not entirely clear
how to set up access to the functions in C#. By PInvoke I presume you mean
dllimport, so for a function like this:

DWORD PfCreateInterface(
DWORD dwName,
PFFORWARD_ACTION inAction,
PFFORWARD_ACTION outAction,
BOOL bUseLog,
BOOL bMustBeUnique,
INTERFACE_HANDLE* ppInterface
);

I presume the set up to dllimport would be something like this (and this is
a big guess):

[dllimport ("iphlpapi.dll")]
public static extern int pfCreateInterface(int dwName, int inAction, int
OutAction, bool bUseLog, bool bMustBeUnique, intptr ppInterface);

The actual information on the MSDN sites for these packet filtering
functions is pretty sparse, but I think if I can find enough code samples I
can figure it out. Any pointers would be appreciated.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
5
by: thorley | last post by:
Greetings, I'm interested in a simple content-based internet firewall/filter, similar to dansguardian (http://dansguardian.org/), but written in python, and for windows. I assumed such a project...
23
by: Marco | last post by:
Could anyone please tell me why the program has the following error? I copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ...
1
by: rada.lambretha | last post by:
Configuring Linux as a Firewall * Making installation choices * Introducing iptables * Using iptables commands * Simplifying things with firewall GUIs * Adding proxy functionality As...
6
by: The D0ct0r | last post by:
Hi People, I am working on a tcp client/server, using this tutorial: http://tldp.org/ LDP/LG/issue74/tougher.html Everything works fine, as long as I connect to my own machine (localhost) When...
3
by: Python | last post by:
On 22 okt 2008, at 13:50, ryan fox wrote: does it work if you temporarily switch off the firewall? gr Arno
0
by: MstAsg | last post by:
Hi, I have question about network programming. My first question was probably about the platform, because the speed and the user friendliness is important. I decided to do it in VC++, not in .net...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.