locked
Ping IpAddress with Port number?

    Question

  • 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

    Wednesday, May 02, 2007 8:03 AM

Answers

  • 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

    Wednesday, May 02, 2007 6:05 PM

All replies

  • 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.
    Wednesday, May 02, 2007 3:29 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.

    Best Regards,

    Rizwan aka RizwanSharp

    Wednesday, May 02, 2007 6:05 PM
  • 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...

    Wednesday, May 02, 2007 6:20 PM
  • 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!
    Thursday, May 03, 2007 12:38 AM
  • 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!
    Saturday, July 28, 2007 5:39 AM
  • hahaha!

    Thursday, November 15, 2007 12:19 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

    goodluck

     

     

     

    Monday, March 24, 2008 9:00 AM
  • You can't ping port number.
    • Edited by CaddreModerator Thursday, July 24, 2008 8:17 PM removed insult
    • Proposed as answer by Marcin Kalkus Thursday, October 06, 2011 6:45 AM
    Tuesday, March 25, 2008 10:35 AM
  • As somebody previously said you cannot ping a port but if you have a telnet client you should be able to telenet to it.
    Monday, July 21, 2008 6:08 PM
  • Yes 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.
    Javaman
    Tuesday, July 22, 2008 11:58 AM
  • 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
    Sunday, June 13, 2010 12:05 PM
  • 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 4:37 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.

    Jessi

    Thursday, August 12, 2010 8:27 AM
  • 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[0];
    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("107.108.1.179"); 
    
    

     


    Javaman
    • Proposed as answer by Jack Moxley Wednesday, August 10, 2011 3:52 PM
    Friday, August 13, 2010 12:33 PM
  • Try Paping (http://code.google.com/p/paping/), it's like ping but for ports.
    Wednesday, September 01, 2010 7:59 PM
  • Now, you are not actually Jessica Alba, now are you? 
    Friday, April 08, 2011 9:36 AM
  • 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.

    Good luck

     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
    Thursday, May 26, 2011 11:56 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. 
    Javaman, Cowboy Coders Unite!
    • Proposed as answer by Jack Moxley Wednesday, August 10, 2011 3:52 PM
    • Unproposed as answer by Jack Moxley Wednesday, August 10, 2011 3:53 PM
    Wednesday, June 08, 2011 11:17 PM
  • SPELLCHECK would be good!

    Most browsers have them, and if they don't you can find plug-ins to do it.
    Wednesday, August 10, 2011 3:51 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. 
    Javaman, Cowboy Coders Unite!
    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.
    Saturday, August 20, 2011 12:20 PM
  • Sorry 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!
    Wednesday, September 21, 2011 2:56 PM