koldfront

Quick "host is up" #commandline #email #net

Using ping(8) to determine whether a host on the local network is up is easy, but a bit slow - especially if what you are doing is checking whether it makes sense to ask the jukebox what song is playing, so you can add an X-Now-Playing: header to the email/article you are composing.

So I went hunting for someting quicker, and came up with this little script, using nmap(1):

  #!/bin/sh
  CHECK=$1
  nmap -PS --max-retries 1 --max-rtt-timeout 20ms --host-timeout 20ms $CHECK | grep --quiet 'Host is up'
  RET=$?
  if [ $RET = 0 ]; then
      echo "UP"
  else
      echo "DOWN"
  fi
  exit $RET

Works nicely.

Add comment?

Title:

Name:

Email (won't be displayed online):

Text:

0.0176 s
webcustodian@koldfront.dk