Wednesday, May 02, 2007 8:03 AM
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.
Wednesday, May 02, 2007 3:29 PMThere'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.
Wednesday, May 02, 2007 6:05 PM
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.
Rizwan aka RizwanSharp
- Marked As Answer by CaddreModerator Thursday, July 24, 2008 8:18 PM
Wednesday, May 02, 2007 6:20 PM
If your looking for a port scanner, use somthing like...Code Snippet
Public Sub PortScan()
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)
For Port As Integer = StartPort To EndPort
Console.Write("Current Port: " & Port)
If ScanPort(System.Net.IPAddress.Parse(IP), Port) = True Then
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 & ", ")
Console.WriteLine(vbCrLf & "Invalid IP specified, Please try again...")
ReadOnly Property ScanPort(ByVal IP As System.Net.IPAddress, ByVal Port As Integer) As Boolean
Dim TCP As New System.Net.Sockets.TcpClient
If TCP.Connected = True Then
ScanPort = True
ScanPort = False
It's a bit slow, but if you run the 'ScanPort' property on several threads then you can speed the process up considerably.
- Proposed As Answer by CaddreModerator Thursday, July 24, 2008 8:18 PM
Thursday, May 03, 2007 12:38 AM
how disappointing! i don't want to use socket because it will raise socketException and that will slow tremendously the overall process.
- Unmarked As Answer by CaddreModerator Thursday, July 24, 2008 8:18 PM
Saturday, July 28, 2007 5:39 AMWOW........... 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!
Thursday, November 15, 2007 12:19 AM
Monday, March 24, 2008 9:00 AM
check by pinging
ping ipaddress portnumber
eg: ping 192.168.1.1 500
check the port is availble or not
if u find something else let me know
Tuesday, March 25, 2008 10:35 AMYou can't ping port number.
Monday, July 21, 2008 6:08 PMAs somebody previously said you cannot ping a port but if you have a telnet client you should be able to telenet to it.
Tuesday, July 22, 2008 11:58 AMYes and what does telnet do? It attempts to open a socket to whatever port you specify on the command. The only way to do this is as was mentioned before, write a socket client that attempts to open by port number.
Sunday, June 13, 2010 12:05 PM
The best method is
Telnet <IP ADDRESS> <Port Number>
if the port is opened you will see a blank screen in command prompt....
- Proposed As Answer by bednsrnsny Monday, June 25, 2012 9:37 AM
Thursday, August 12, 2010 4:37 AM
hi Jessica ,
you can use portquery utility to check the port status of the Ip address.
Download the Port Query .
eg : portqry -n ip address -e port number.
- Proposed As Answer by Fedor Steeman Friday, April 08, 2011 9:36 AM
Thursday, August 12, 2010 8:27 AM
well, this seems to be a good stuff. how do i use this in the code of my .NET C# application? sorry, i am a total newbie just joined the IT industry. pls bear with me.
Friday, August 13, 2010 12:33 PM
Look into Sockets, forget Telenet.... If you want a fast Port Scanner you will want to use Asynchronous Socket code. If you don't need super fast port scanning you would use Synchronous Socket code.
Here's the idea, for a synchronous port scanner all you want to do is send a single packet to IP address/Port pair. An IP Address/Port Pair is called a socket. Here's the pseudo code:
TcpClient tcpClientC = new TcpClient (); IPAddress ipAddress = Dns.GetHostEntry ("www.contoso.com").AddressList; tcpClient.Connect (ipAddress, 11003);
That's all that needs to be done, and here's why... You are not trying to doing anything more than get a response from an specific IP/Port pair. Therefore, the connect will do that. If the connect fails, an error will be thrown. The error will be the "signature" of a failed open. So there's really only two conditions that will happen 1) It gets connected, 2) It doesn't
Use this class:
http://msdn.microsoft.com/en-us/library/7x80fwhz.aspx NOTE if you don't want to use a DNS Resolve you can pass a string which would be more friendly for iterating addresses.
System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("220.127.116.11");
- Proposed As Answer by Jack Moxley Wednesday, August 10, 2011 3:52 PM
Wednesday, September 01, 2010 7:59 PMTry Paping (http://code.google.com/p/paping/), it's like ping but for ports.
Friday, April 08, 2011 9:36 AMNow, you are not actually Jessica Alba, now are you?
Thursday, May 26, 2011 11:56 PM
Jessica, if you're still looking for an answer I have it.
Go to this link http://www.angryip.org/w/Download. It's exactly what anyone needs to find out if a single port, or ports, are open after only a little bit of setup.
After downloading Click Options, then select Options - I suggest you change these defaults to start off with;
Change 20mS to 200mS or longer - this will allow the scanner to dwell longer on an IP address in order to confirm multiple ports.
Change All hosts to Only Alive, then click OK and Save.
Click Options again then select Ports. Type in the ports you are interested in separated by commas. Click OK.
Click Options yet again, then Click Save Options.
You can scan a single IP or a range of addresses.
It works really well and you may find other ways to tweak its use after playing around with it a bit.
I forgot to mention. The utiility is free, but, some antivirus software will detect it as being a 'bad thing' since it can be used by 'bad people'. It's one tool that the 'bad people' can use to scan for open ports on systems in order to find backdoor entry methods. Usually you can ADD it to a safe list so you don't keep getting prompted. I use this ALL THE TIME where I work where they are very much afraid of the network being compromised.SPELLCHECK would be good!
- Edited by 905benchguy Friday, May 27, 2011 12:14 AM reworded
Wednesday, June 08, 2011 11:17 PMFYI.... This is no ability now or will there ever be the ability to Ping by PORT. Ping runs at ICMP layer which is one layer below the TCP/IP layer. ICMP has no concept of a port.
Javaman, Cowboy Coders Unite!
Wednesday, August 10, 2011 3:51 PM
SPELLCHECK would be good!Most browsers have them, and if they don't you can find plug-ins to do it.
Saturday, August 20, 2011 12:20 PM
FYI.... This is no ability now or will there ever be the ability to Ping by PORT. Ping runs at ICMP layer which is one layer below the TCP/IP layer. ICMP has no concept of a port.Careful! That depends on what you mean by "ping". You have to be careful when working with higher level languages, because they may have what they call a "ping" function which uses something other than a standard ICMP ping packet. For example in Java there are certain situations where it will attempt to open a TCP connection on a specific port #, and others where it will actually generate a true ICMP ping packet.
Javaman, Cowboy Coders Unite!
Wednesday, September 21, 2011 2:56 PMSorry Ngroth but I respectfully disagree with you. If other higher level applications bastardize the definition of the word Ping that is their problem. Ping is well defined to run at ICMP layer and has been for 20 years or more. But as we programmers know context of words is everything, so yes you are correct in that stolen terms happen all the time. But to be clear, the developer must be able to discern true Ping from false Ping.
Javaman, Cowboy Coders Unite!