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

Solution 1:

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)

Solution 2:

Answer useful for Docker

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:

Run an SNMP agent on the remote machine, and use a manager to read one of the values out of the standard MIB.


Solution 4:

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 5:

If you have not firewalls and routers in the way, i.e., if you're on the same segment as the host you're trying to check - most of the solutions above are a little exhaustive imho.

It doesn't matter what port you connect to, and in fact, if you connect to a port that's unlikely to have a service running, you can get the job done without being detected.

How?

You can use any tool you like, but we can just use telnet...

% telnet <host> 313373
Trying 10.211.55.3...
telnet: connect to address 10.211.55.3: Connection refused
telnet: Unable to connect to remote host
%

This should happen immediately, unless the host is dropping packets. What's actually happening is that the TCP/IP stack on the host is sending you back a TCP segment with the RST bit set - i.e. terminating your SYN packet.

The fact that you received a RST packet means that there is indeed a host up at the other end, and as a bonus - you've done so undetected (The TCP/IP had no upper-layer application to talk to about this connection).

Rather than telnet however, I'd probably use something like scapy, write up something that looks for the RST flag and let's you know.

Just to complete this, if there is no host on the IP that you try - it will hang for a little while, and the timeout - the same thing that would happen if the receiving host had a firewall with a drop filter.

If firewalls are involved, then as others have suggested, make use of tools such as nmap and whatever else.

Tags:

Ping