Commands tagged ping (48)

  • If you're very busy and don't want to wait for a ping response, use it. This command will be waiting for a successful ping response, to play a sound file to warn you that the target host is available.


    0
    continuar=true; while $continuar; do if ping -c 3 [target_IP_address] 2>&1> /dev/null ; then mplayer [sound_file]; continuar=false; break; fi; done
    mack · 2011-04-25 21:44:05 18
  • pcspkr have to be enabled! modprobe pcspkr xset b on


    0
    ping -a IP-ADDRESS
    markussesser · 2011-04-28 13:51:12 23
  • Change the IP address from 127.0.0.1 to the target machines ip address. Even if the target has ICMP (ping) blocked, it will show you what ports are open on the target. Very handy for situations where you know the target is up and online but wont respond to pings. Show Sample Output


    0
    nmap -sT -PN -vv <target ip>
    Richie086 · 2011-07-22 02:37:19 8
  • export THISOS="`uname -s`" if [ "$THISOS" = "SunOS" ] then export THISRELEASE="`uname -r`" ping1() { ping -s $1 56 1 | egrep "^64"; } elif [ "$THISOS" = "AIX" ] then export THISRELEASE="`uname -v`.`uname -r`" ping1() { ping -w ${2:-1} $1 56 1 | egrep "^64"; } elif [ "$THISOS" = "Linux" ] then export THISRELEASE="`uname -r`" ping1() { ping -c 1 -w ${2:-1} $1 | egrep "^64"; } fi


    0
    ping1 IPaddr_or_hostname
    waibati · 2012-02-09 17:26:32 3
  • This version combines the best of the other suggestions and adds these features: 1. It scans a /16 subnet 2. It is very fast by running the ping commands in the background, running them in parallel. 3. Does not use the "-W" option as that's not available in older ping versions (I needed this for OS X 10.5)


    0
    prefix="169.254" && for i in {0..254}; do echo $prefix.$i/8; for j in {1..254}; do sh -c "ping -m 1 -c 1 -t 1 $prefix.$i.$j | grep \"icmp\" &" ; done; done
    tempelorg · 2012-07-25 12:07:15 3
  • Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system. Maybe there's an easier way to set a timeout in the ssh options...


    0
    for host in $MYHOSTS; do ping -q -c3 $H 2>&1 1>/dev/null && ssh -o 'AllowedAuthe ntications publickey' $host 'command1; command2' & for count in 1 2 3 4 5; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done
    a8ksh4 · 2012-11-13 23:12:27 5
  • Cleaned up and silent with &>/dev/null at the end. Show Sample Output


    0
    for host in $HOSTNAMES; do ping -q -c3 $host && ssh $host 'command' & for count in {1..15}; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done &>/dev/null
    somaddict · 2012-11-16 02:31:27 4
  • Super fast way to ftp/telnet/netcat/ssh/ping your loopback address for testing. The default route 0.0.0.0 is simply reduced to 0. Show Sample Output


    0
    telnet 0 <port>
    somaddict · 2012-11-16 03:38:49 4
  • This helps me determine which repo I want to use for downloading ISO files Show Sample Output


    0
    cat repos.txt | while read line; do echo $line | cut -d"/" -f 3 | fping -e ;done
    rawm · 2015-02-17 06:34:07 8
  • Changelog: Changing ping to "ping -A -c1 -w10" - targeting a quick and reliable ping, even on slow networks.


    0
    ADDR=127.0.0.1 ; for i in `seq 1300 1501`; do echo -ne "Pacote de tamanho $i bytes" ; ping -A -c1 -w10 -s $i -Mdo $ADDR 2>&1 > /dev/null || break ; echo -ne "\r\033[2K" ; done ; echo -ne "\r\033[2K" ; echo -e "MTU bem sucedido com `expr $i`"
    pqatsi · 2015-12-18 18:11:47 11
  • IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type powershell Uses sajb to start a PowerShell background job that pings an IP host every 10 seconds. Any changes in the host's Up/Down state is time-stamped and logged to a file. Date/time stamps are logged in two formats: Unix and human-readable. A while(1) loop repeats the test every 10 seconds by using the sleep command. See the Sample Output for more detail. I use this command to log Up/Down events of my Motorola SB6141 cable modem (192.168.100.1). To end the logging, close the PowerShell window or use the "exit" command. Show Sample Output


    0
    sajb {$ip="192.168.100.1";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}
    omap7777 · 2015-12-28 20:33:08 15
  • activate the first alert and the next ones are activated automatically. Show Sample Output


    0
    curl ping.gl
    wuseman1 · 2022-10-15 13:24:45 868
  • Bash scrip to test if a server is up, you can use this before wget'ing a file to make sure a blank one isn't downloaded.


    -1
    if [ "$(ping -q -c1 google.com)" ];then wget -mnd -q http://www.google.com/intl/en_ALL/images/logo.gif ;fi
    alf · 2010-03-23 04:15:03 10
  • This command are using by me for checking connection with Internet. Show Sample Output


    -1
    while true; do /bin/ping -q -c1 -w3 8.8.8.8 2>&1 > /dev/null || echo "8.8.8.8 ping failed at $(date +%d/%m/%y) $(date +%H:%M:%S)" >> /var/log/ping.log; sleep 10; done &
    Arkey · 2011-05-12 01:51:07 4
  • You need to have mtr installed on your host.


    -1
    mtr google.com
    d_voge · 2012-02-19 22:27:48 3
  • A simple way to find all machines on a network subnet is pinging a broadcast address (-b flag). First run ifconfig ifconfig. Then use "Bcast" address and '-b' flag in ping Show Sample Output


    -1
    ping -b <broadcast address>
    OutputLogic · 2012-05-21 16:55:33 7
  • Not really an easier solution. But an example using && for (if last command returned 0). You can use || for (if last command returned other than 0).. Show Sample Output


    -2
    prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done
    xeor · 2010-04-07 17:17:21 4

  • -2
    for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
    wiburg · 2010-06-12 18:38:36 3
  • Every 20 minutes ping host with IP address 192.168.0.14. If it's not 'alive' or not reachable, then display something eye-catching (here xeyes) on the desktop. Hint for newbies: edit crontab with crontab -e


    -2
    10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || env DISPLAY=:0 xeyes
    knoppix5 · 2012-02-06 09:40:11 3
  • sending packet by ping if sending more high packet root needed... Show Sample Output


    -3
    sudo ping -f -c 999 -s 4500 target.com
    gunslinger_ · 2010-07-11 16:38:44 13

  • -3
    alias ping='ping -n'
    wincus · 2011-01-19 23:39:21 3
  • Quick and dirty one-liner to get the average ping(1) time from a server. Show Sample Output


    -4
    ping -qc 10 server.tld | awk -F/ '/^rtt/ {print $5}'
    atoponce · 2011-10-12 21:07:06 5
  • Every 20 minutes test if host with IP 192.168.0.14 is 'dead' or not reachable. The line should be put in your crontab file.


    -4
    10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || mail -ne -s'Host 192.168.0.14 not reachable' admin@example.com
    knoppix5 · 2012-02-06 10:42:46 3
  •  < 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

m4a to mp3 conversion with ffmpeg and lame
A batch file version of the same command would be: for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame -ab 256k "${f%.m4a}.mp3"; done

Ease your directory exploration
Usage : tt [OCCURRENCE] tt will display a tree from your actual path tt .svn will display only line containing .svn

move contents of the current directory to the parent directory, then remove current directory.
I think this is less resource consuming than the previous examples

Both view and pipe the file without saving to disk
This is a cool trick to view the contents of the file on /dev/pts/0 (or whatever terminal you're using), and also send the contents of that file to another program by way of an unnamed pipe. All the while, you've not bothered saving any extra data to disk, like you might be tempted to do with sed or grep to filter output.

Sort by IP address

continuously print string as if being entered from the keyboard
Cycles continuously through a string printing each character with a random delay less than 1 second. First parameter is min, 2nd is max. Example: 1 3 means sleep random .1 to .3. Experiment with different values. The 3rd parameter is the string. The sleep will help with battery life/power consumption. $ cycle 1 3 $(openssl rand 100 | xxd -p) Fans of "The Shining" might get a kick out of this: $ cycle 1 4 ' All work and no play makes Jack a dull boy.'

A very quick and slick fork bomb. Handle with care. Don't run on production please...

Replace spaces in filenames with underscores

Check a directory of PNG files for errors
Useful for checking if a large number of PNG files was downloaded successfully by verifying the built-in CRC checksum. For incomplete files, the command will print: "00002309.png EOF while reading IDAT data ERROR: 00002309.png" The process is very fast; checking 21,000 files of 5MB in size took only five minutes on a 2011 Intel mobile dual-core.

Netcat ftp brute force


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: