Jessica Alba

I am using System.Net.NetworkInformation with Ping method.

But it seems like it can only ping IPAddress. What should I need to do if I need to find out whether a port of the IPaddress is available

Let me know. I will reward you.

Thanks



Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

micvos

There's no method available to find a port. You could try just sending something and see if you get something back but it's not very reliable. Nor is ping by the way. Most machines have blocked the ping functionality.




Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

RizwanSharp

There is no way to do this with Ping. Ping only tells you that if any computer is online / connected to network to be accessed or not. It'll not tell you that if a specific port of that machine is opened or not....

You can use TcpClient class od System.Net.Sockets namespace to connect to some specific port to a given IP Address. If connection is established.... It means port is opened otherwise exception will be raised (Check SocketError of SocketException) to determine what was the cause of problem. In your case, if SocketError code is 10061 then you may think that port is closed.

Best Regards,

Rizwan aka RizwanSharp






Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

Lenord...

Hi there,

If your looking for a port scanner, use somthing like...

Code Snippet

Public Sub PortScan()
Console.Clear()
Console.WriteLine("Please Enter IP address: ")
Dim IP As String = Console.ReadLine()
Console.WriteLine("Please Enter Starting Port: ")
Dim StartPort As Integer = Console.ReadLine()
Console.WriteLine("Please Enter End Port: ")
Dim EndPort As Integer = Console.ReadLine()

Dim ListOfPorts As New List(Of Integer)
Try
For Port As Integer = StartPort To EndPort
Console.SetCursorPosition(0, 7)
Console.Write("Current Port: " & Port)
If ScanPort(System.Net.IPAddress.Parse(IP), Port) = True Then
ListOfPorts.Add(Port)
End If
Next

Console.WriteLine(vbCrLf & "List of Open Ports on: " & IP & " (" & System.Net.Dns.GetHostEntry(System.Net.IPAddress.Parse(IP)).HostName & ")")
For Each Port As Integer In ListOfPorts
Console.Write(Port & ", ")
Next
Catch
Console.WriteLine(vbCrLf & "Invalid IP specified, Please try again...")
End Try

End Sub

ReadOnly Property ScanPort(ByVal IP As System.Net.IPAddress, ByVal Port As Integer) As Boolean
Get
Dim TCP As New System.Net.Sockets.TcpClient
Try
TCP.Connect(IP, Port)
Catch
End Try
If TCP.Connected = True Then
ScanPort = True
TCP.Close()
Else
ScanPort = False
TCP.Close()
End If

End Get
End Property

It's a bit slow, but if you run the 'ScanPort' property on several threads then you can speed the process up considerably.

Lenord...






Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

cl408e

how disappointing! i don't want to use socket because it will raise socketException and that will slow tremendously the overall process.

i don't care! give me a solution, now!




Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

Sniper167

WOW........... I think someone woke up on the wrong side of the bed! Take a chillpill! I don't think you are going to get an answer asking like that!





Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

szaranger

Must be an Indian ..






Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

Watashi_me

must be an american





Re: .NET Framework Networking and Communication Ping IpAddress with Port number?

Sniper167

hahaha!