471,319 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

port blocking

Does anyone know of a way, using C#, to programmatically block a
Windows port? I've looked into some low level solutions like NDIS, but
am hoping to find something that uses C#. Any help would be greatly
appreciated.

Feb 16 '06 #1
6 8894
Hi,

"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Does anyone know of a way, using C#, to programmatically block a
Windows port? I've looked into some low level solutions like NDIS, but
am hoping to find something that uses C#. Any help would be greatly
appreciated.


No, there is nothing like that that I know of, I would suggest you check WMI
first , additionally see if the firewall that comes with SP2 has any API
you can use.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 17 '06 #2
Thanks Ignacio, I have been looking through WMI, it's just hard to know
where to even start. There is some stuff is SP2 and even more
planned/coming for the future. I was hoping to find something .NET
based b/c our app needs to work on XP as well as 2000.

I'll keep looking through WMI and I'll post an answer if I find one.

Feb 17 '06 #3

"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
| Thanks Ignacio, I have been looking through WMI, it's just hard to know
| where to even start. There is some stuff is SP2 and even more
| planned/coming for the future. I was hoping to find something .NET
| based b/c our app needs to work on XP as well as 2000.
|
| I'll keep looking through WMI and I'll post an answer if I find one.
|

The easiest is to shell-out (built-in) firewall configuration to the
netsh.exe command line utility.

For instance running:
netsh firewall show portopening
returns all ports open, while..

netsh firewall add portopening TCP 80 myport80

opens port 80 for TCP traffic

or:

add portopening protocol = TCP port = 135 name = DNS mode = ENABLE
scope = CUSTOM addresses =
192.168.0.1,192.168.0.0/16,10.0.0.0/255.0.0.0,LocalSubnet

for more info run - netsh firewall ?

Willy.


Feb 17 '06 #4
Willy,

I've been reading through the docs on netsh and it looks to be exactly
what I want, but I haven't been able to successfully block a port yet.

Specifically, I want to be able to turn on/off port 8080 to block
internet traffic. Does netsh allow you to completely block a port and
then later re-enable it? If so, what would be the syntax to do that?

Thanks again for your help.

Feb 17 '06 #5

"JustinC" <ju***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Willy,
|
| I've been reading through the docs on netsh and it looks to be exactly
| what I want, but I haven't been able to successfully block a port yet.
|
| Specifically, I want to be able to turn on/off port 8080 to block
| internet traffic. Does netsh allow you to completely block a port and
| then later re-enable it? If so, what would be the syntax to do that?
|
| Thanks again for your help.
|

Here are some examples:

Add an entry to all profiles, name = Web, default mode = DISABLE for port
tcp/8080
netsh firewall add portopening protocol = TCP port = 8080 name = Web mode =
DISABLE profile = all

Disable port
netsh firewall set portopening TCP 8080 Web DISABLE

Enable the port
netsh firewall set portopening TCP 8080 Web ENABLE

Show status of all profiles in verbose mode
netsh firewall show portopening ENABLE
Willy.
Feb 18 '06 #6
ok, that's what I was doing, it just wasn't doing what I was hoping it
would do. I'm trying to find a way to programmatically block all
internet traffic to a computer without blocking other network traffic.
I guess even with port 80 and 8080 blocked, outgoing traffic must
either produce an exception to allow incoming traffic, or another port
is being used. Thanks for all the help. Back to the drawing board!

Feb 19 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by lazydb2dba | last post: by
3 posts views Thread by collinm | last post: by
3 posts views Thread by Bill | last post: by
2 posts views Thread by jasonsgeiger | last post: by
2 posts views Thread by findyasir | last post: by
25 posts views Thread by bmearns | last post: by
1 post views Thread by Andy Bates | last post: by
reply views Thread by rosydwin | last post: by

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.