Commands tagged ping (48)

  • Works on any machine with nmap installed. Previous version does not work on machines without "seq". Also works on subnets of any size. Show Sample Output


    21
    nmap -sP 192.168.1.0/24
    sdadh01 · 2010-06-05 14:48:37 9
  • pings a server once per second, and beeps when the server is unreachable. Basically the opposite of: ping -a server-or-ip.com which would beep when a server IS reachable. You could also substitute beep with any command, which makes this a powerful alternative to ping -a: while true; do [ "$(ping -c1W1w1 server-or-ip.com 2>/dev/null | awk '/received/ {print $4}')" = 1 ] && date || echo 'server is down!'; sleep 1; done which would output the date and time every sec until the ping failed, in which case it would echo. Notes: Requires beep package. May need to run as root (beep uses the system speaker) Tested on Ubuntu which doesn't have beep out of the box... sudo apt-get install beep


    14
    while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
    sudopeople · 2009-03-31 20:47:56 14
  • Usefull for when you don't have nmap and need to find a missing host. Pings all addresses from 10.1.1.1 to 10.1.1.254, modify for your subnet. Timeout set to 1 sec for speed, if running over a slow connection you should raise that to avoid missing replies. This will clean up the junk, leaving just the IP address: for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from' | cut -d' ' -f 4 | tr -d ':'; done Show Sample Output


    14
    for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
    SuperJediWombat · 2010-04-07 16:57:53 7
  • This command uses ping to get the routers' IP addresses to the destination host as traceroute does. If you know what I mean..


    12
    for i in {1..30}; do ping -t $i -c 1 google.com; done | grep "Time to live exceeded"
    6bc98f7f · 2012-02-19 13:37:04 8
  • PING parameters c 1 limits to 1 pinging attempt q makes the command quiet (or silent mode) /dev/null 2>&1 is to remove the display && echo ONLINE is executed if previous command is successful (return value 0) || echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself). I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done. Asking for the machine name or IP Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).


    9
    ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
    UnixNeko · 2012-02-09 06:30:55 26
  • Joker wants an email if the Brand X server is down. Set a cron job for every 5 mins with this line and he gets an email when/if a ping takes longer than 3 seconds. Show Sample Output


    8
    ping -q -c1 -w3 brandx.jp.sme 2&>1 /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
    mccalni · 2009-10-13 14:13:04 16
  • When run on a mac, this command will bring up a dialog box in the Terminal when server HOSTNAME first responds to a ping.


    7
    ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
    neologism · 2009-08-03 16:06:57 4
  • It really disables all ICMP responses not only the ping one. If you want to enable it you can use: sudo -s "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all"


    6
    sudo -s "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all"
    sliceoflinux · 2010-06-22 19:16:43 14
  • Audio acknowledgement for host availability. When running the command from a Linux systems, you can use "festival" or "espeak" instead of "say".


    6
    Mac OSX: ping -oc 30 8.8.4.4 > /dev/null && say "Google name server is up" || say "This host is down"
    raulyca · 2014-08-01 15:44:57 6
  • Ping sweep without NMAP


    3
    for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
    hemanth · 2009-08-22 09:34:27 12
  • Waits for all pings to complete and returns ip with mac address


    3
    (prefix="10.59.21" && for i in `seq 254`; do (sleep 0.5 && ping -c1 -w1 $prefix.$i &> /dev/null && arp -n | awk ' /'$prefix'.'$i' / { print $1 " " $3 } ') & done; wait)
    smoky · 2014-04-02 11:20:57 10
  • After this, just type: beepwhenup You need to install "beep" before this would make the beep sound. Save it in your .profile if you want to use it later WARNING: this command won't exit until it is successful. You won't be able to CONTROL+C out of it.


    2
    beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
    linuxrawkstar · 2009-09-24 18:11:10 7
  • Alternative to the ping check if your firewall blocks ping. Uses curl to get the landing page silently, or fail with an error code. You can probably do this with wget as well. Show Sample Output


    2
    curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
    mccalni · 2009-10-23 14:29:06 4
  • For some reason the 2&>1 does not work for me, but the shorter stdout/stderr redirection >& works perfectly (Ubuntu 10.04).


    2
    ping -q -c1 -w3 server.example.com >& /dev/null || echo server.example.com ping failed | mail -ne -s'Server unavailable' admin@example.com
    brainstorm · 2010-09-08 12:19:29 4

  • 2
    ping HOSTNAME | while read pong; do echo "$(date): $pong"; done
    sammcj · 2011-09-07 02:03:19 43
  • Cleaner with a mailto assignment in crontab (if the command fails you get an email): MAILTO=admin@example.com 10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 >/dev/null


    2
    10,30,50 * * * * ping -c1 -w3 192.168.0.14 >/dev/null
    bashrc · 2012-02-06 14:54:15 3
  • Nasty perl one-liner that provides a sparkline of ping times. If you want a different history than the last 30, just put that value in. It (ab)uses unicode to draw the bars, inspired by https://github.com/joemiller/spark-ping . It's not the most bug-free piece of code, but what it lacks in robustness it makes up for in capability. :) If anyone has any ideas on how to make it more compact or better, I'd love to hear them. I included a ping to google in the command just as an example (and burned up 10 chars doing it!). You should use it with: $ ping example.com | $SPARKLINE_PING_COMMAND Show Sample Output


    2
    ping g.co|perl -ne'$|=/e=(\S+)/||next;(push@_,$1)>30&&shift@_;print"\r",(map{"\xe2\x96".chr(128+7*$_/(sort{$b<=>$a}@_)[0])." "}@_),"$1ms"'
    bartgrantham · 2012-07-06 22:42:06 3

  • 2
    nmap -sn 192.168.1.0/24
    pdxdoughnut · 2014-01-28 23:32:18 12
  • Will report back IP address's of all hosts that are UP. Show Sample Output


    2
    fping -ga 192.168.1.0/24 2> /dev/null
    netaxiz · 2014-01-31 19:19:19 11
  • This allows for sleeping in between pings. Also, espeak needs to be installed.


    2
    speakwhenup() { [ "$1" ] && PHOST="$1" || return 1; until ping -c1 -W2 $PHOST >/dev/null 2>&1; do sleep 5s; done; espeak "$PHOST is up" >/dev/null 2>&1; }
    aguslr · 2014-11-26 10:22:18 7
  • This command only check the network connection from given eth. This is very useful if you are using more then one interface in your server or laptop. Show Sample Output


    1
    ping -I eth0 www.yahoo.com
    octopus · 2010-04-12 06:25:07 3
  • This is like ping -a, but it does the opposite. It alerts you if the network is down, not up. Note that the beep will be from the speaker on the server, not from your terminal. Once a second, this script checks if the Internet is accessible and beeps if it is not. I define the Net as being "UP", if I can ping Google's public DNS server (8.8.8.8), but of course you could pick a different static IP address. I redirect the beep to /dev/console so that I can run this in the background from /etc/rc.local. Of course, doing that requires that the script is run by a UID or GID that has write permissions to /dev/console (usually only root). Question: I am not sure if the -W1 flag works under BSD. I have only tested this under GNU/Linux using ping from iputils. If anybody knows how portable -W is, please post a comment.


    1
    while :; do ping -W1 -c1 -n 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done
    hackerb9 · 2010-09-24 06:34:12 7
  • I have used single packet, and in a silent mode with no display of ping stats. This is with color and UI improvement to the http://www.commandlinefu.com/commands/view/10220/check-if-a-machine-is-online. It is as per the enhancements suggested. Show Sample Output


    1
    echo -n "IP Address or Machine Name: "; read IP; ping -c 1 -q $IP >/dev/null 2>&1 && echo -e "\e[00;32mOnline\e[00m" || echo -e "\e[00;31mOffline\e[00m"
    crlf · 2012-02-09 07:00:03 9
  • Online games have pretty good lag compensation nowadays, Sometimes though, you really want to get some warning about your latency, e.g. while playing Diablo III in Hardcore mode, so you know when to carefully quit the game b/c your flatmate started downloading all his torrents at once. This is done on Darwin. On Linux/*nix you would need to find another suitable command instead of `say` to spell out your latency. And I used fping because it's a little bit easier to get the latency value needed. Something similar with our regular ping command could look like this: while :; do a=$(ping -c1 google.com | grep -o 'time.*' | cut -d\= -f2 | cut -d\ -f1 | cut -b1-4); [[ $a > 40 ]] && say "ping is $a"; sleep 3; done


    1
    while :; do a=$(fping -e google.de | grep -o '[0-9]+.[0-9]+'); [[ $a > 40 ]] && say "ping is $a"; sleep 3; done
    rxw · 2015-09-21 02:14:02 38

  • 0
    for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl
    takeshin · 2010-06-05 13:15:06 4
  •  1 2 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: