473,385 Members | 1,343 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,385 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 9198
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lazydb2dba | last post by:
I would like to know if there is any reason that a connection port is not listening. I've found the following message in my db2diag.log DIA3003E Error encountered in "TCPIP" protocol support....
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
3
by: Bill | last post by:
I'm trying to use Enterprise Manager to manage my remote SQL database, but I can't seem to get a connection. I think my cable ISP Comcast may be blocking the port EM uses. What port does...
2
by: Jim | last post by:
Tried a search, but didn't find quite what I was looking for. Situation: Have a VBA code process, tapping CDOSYS to send e-mail from Access, attaching an Excel spreadsheet, to a given list of...
2
by: jasonsgeiger | last post by:
From: "Factor" <jasonsgeiger@gmail.com> Newsgroups: microsoft.public.in.csharp Subject: Multiple Clients, One port Date: Wed, 19 Apr 2006 09:36:02 -0700 I'm been working with sockets for a...
2
by: findyasir | last post by:
Hi all, I am having problem comunication with serial port in linux. I have tested the serial port with attaching a serial modem and dialing the numbers with wvdial. it works okie but when i...
25
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's...
1
by: Andy Bates | last post by:
Hi - Can't see another newsgroup to post this in; so thought I'd post here. I have a C# application that relies on multicast UDP to detect how many PCs the application is executing on...
0
by: thesti | last post by:
hello, i'm trying to connect to SQL Server 2000 on my localhost through JDBC. i'm using the Microsoft SQL Server JDBC Driver 2.0 i couldnt make it, as i get the following error Unable to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.