44

I'm trying to use GeekTool (Mac pref pane... basically just embeds output of a shell command/script on the desktop... http://lifehacker.com/#!244026/geek-to-live--monitor-your-mac-and-more-with-geektool) to monitor a a remote machines/server, and I'm having some trouble determining how best to check if a machine is up/down.

I'm using no-ip as a free dns re-direct... but this only helps me with the public IP of the router. The machine I want is behind the router and thus isn't able to be "ping"ed directly.

I have port forwarding set up for port 8080 which leads to the machine I want. Is there a way to essentially ping through port 8080 to see if the machine is up and running? I tried telnet, but this apparently doesn't work (as far as output) in GeekTool. I'm running a website at 8080, so I guess I just want to know if/when it goes down.

Thanks in advance... if I can provide more clarification let me know.

(figured out my problem... see below)

1
  • 3
    ping is an ICMP protocol, whereas ports are TCP and UDP concepts. All 3 are distinct protocols on top of IP. That means an IP packet containing TCP cannot contain ICMP and vice versa. It also means the TCP header (with the port) is not present in an ICMP ping packet.
    – MSalters
    Commented Dec 30, 2013 at 13:33

4 Answers 4

42

To check a specific port, you can use telnet:

telnet 127.0.0.1 8080

(The port follows the IP / hostname with a space, not a colon.)

If you get an immediate error, then the port is not available. If telnet hangs, then you have successfully connected to the port. Ctrl + C to kill telnet, then.

This may or may not help with the port forwarding issue, though. It just gets you to that IP and port.

3
  • This would get the job done... but it doesn't work with GeekTool :/. I appreciate the help.
    – loeschg
    Commented Apr 22, 2011 at 19:15
  • 10
    You might need to run brew install telnet to install telnet. Commented Apr 1, 2019 at 15:35
  • Keep in mind this only works for TCP ports. For UDP ports use netcat : nc -u <host> <port>
    – GwenM
    Commented Jul 20, 2022 at 14:22
10

Theres is hping utility that allows you to ping TCP ports. This is also available via homebrew (brew install hping).

backdrift.org gives a simple instructions on how to use hping for this purpose

$ hping -S -p 80 google.com
HPING google.com (eth0 66.249.92.104): S set, 40 headers + 0 data bytes
len=44 ip=66.249.92.104 ttl=47 id=10442 sport=80 flags=SA seq=0 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=40838 sport=80 flags=SA seq=1 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=64607 sport=80 flags=SA seq=2 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=10443 sport=80 flags=SA seq=3 win=5720 rtt=97.7 ms
^C
--- google.com hping statistic ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 97.7/97.7/97.7 ms
0

You could use wget, curl etc. to check that the website is responding.

3
  • 1
    This only can check a web service port.
    – 244boy
    Commented Nov 15, 2019 at 15:36
  • @244boy The question said "I'm running a website at 8080", so I thought it was a reasonable way to check.
    – Neil
    Commented Nov 15, 2019 at 15:47
  • You can also specify a port using either wget or curl. curl foo.com:564 will get port 564 on whichever IP foo.com resolves to. Same for wget foo.com:564
    – Tijmen
    Commented Sep 10 at 11:30
0

Telnet gets the job done, but I'm unable to integrate that with GeekTool. I ended up doing a mysqladmin ping to the remote machine. The website has a db backend, so this (more-or-less) returns the info I'm looking for. Thanks for all the help!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .