How can I determine if a machine is online without using ping?

I used to use an application that could ping or maybe run a port scan on a machine even if the machine was configured to not allow it.

I am currently trying to ping a remote machine on our WAN, but I have configured the machine to not allow ping. Is there something similar to ping that I can use?

Again, this a machine located in another city that is part of our wan.


Solution 1:

If your using XP/2003+ (this includes Vista/2008/7), then you can use the Win32_PingStatus. The machines inwhich is running the script code is the only system which needs to be XP/2003+, and it works just like using Ping.exe, only it's not using ping.exe so it should act as a loophole to your security setting which does not allow the execution of ping.exe.

strComputer = "192.168.1.1"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_PingStatus " & _
        "Where Address = '" & strComputer & "'")
For Each objItem in colItems
    If objItem.StatusCode = 0 Then 
        WScript.Echo "Reply received."          
    End If
Next

See the Scripting Guy article for more info on how to use Win32_PingStatus:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0914.mspx

Solution 2:

Answer useful for Containers

Ping is ICMP, if you blocked ICMP you can't ping.

You might still be able to test TCP or UDP ports if you are accepting TCP/UDP connections.

If you are running your test on containers, which lack ping, nc, telnet and other tools, you can use this trick:

(echo >/dev/tcp/${host}/${port}) &>/dev/null && echo "open" || echo "closed"

This will attempt to connect through tcp/udp through the device (wow, I know) and echo "open" if the port is open or "closed" if it is closed.

It will hang for a while before echoing "close" when that is the case.

Solution 3:

You can telnet to an open tcp port on the machine. For instance, if the machine is a web server, and has port 80 open, just:

telnet ip.ad.dre.ss 80

This will work even on encrypted ports (although you won't be able to understand the data)

Some other ports to try are:

  • 443 for an https server
  • 22 for ssh

(there is a list of ports/services in /etc/services on linux machines)