Solved

how to use vb.net to check if my winform application is block by firewall TCP/port

Posted on 2011-03-25
3
1,170 Views
Last Modified: 2012-06-21
Hi
I want winform application to be aware of firewall that would block TCP and Port it is using.

Is there such code? to check if firewall is blocking?
0
Comment
Question by:JSW21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Hairbrush earned 500 total points
ID: 35213960
Hi

Yes, it is possible to do this.  You will need to use the System.Net.Sockets namespace in the .NET Framework.  Try the code below:
Dim hostname As String = "server1"
Dim portno As Integer = 9081
Dim ipa As IPAddress = CType(Dns.GetHostAddresses(hostname)(0), IPAddress)
Try
	Dim sock As System.Net.Sockets.Socket = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
	sock.Connect(ipa, portno)
	If sock.Connected = True Then ' Port is in use and connection is successful
			MessageBox.Show("Port is Closed")
	End If
	sock.Close()

Catch ex As System.Net.Sockets.SocketException
	If ex.ErrorCode = 10061 Then ' Port is unused and could not establish connection
		MessageBox.Show("Port is Open!")
	Else
		MessageBox.Show(ex.Message)
	End If
End Try

Open in new window

0
 

Author Closing Comment

by:JSW21
ID: 35217934
sock.close
will allow me to really connect it again later right?
0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 35230399
Yes.
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question