Commands using ping (70)

  • Everytime You Run Bash It Will Run And Send The Command To Background In A Loop Forever. This Is Useful In Android To Avoid Getting Discconnected While Using ADB Or Other Services Like SSH By Being Inactive For Long Periods Of Time. In My Case I Get Bash Full Suport Only Through ADB And Also A Decent Python Interpreter Using Python For Android.


    0
    alias alive='(while true; do ping -c 4 192.168.1.1 > /dev/null 2>&1 ; sleep 300 ; done)'
    DarkXDroid · 2014-06-13 06:13:57 7

  • 0
    mco ping | head -n -4 | awk '{print $1}' | sort
    mrwulf · 2014-06-24 18:20:16 7

  • 0
    ping -c 3 google.com
    nicolasmccurdy · 2014-07-16 02:01:01 8
  • I run into regular problems whereby my cable modem from my ISP will simply stop working. To ensure that it is a problem with my cable modem (and not the router in-between my machine and the cable modem), I needed a quick way to test to someplace beyond the cable modem. The place shouldn't be beyond the cable network though. As such, I needed to determine the gateway to which my cable modem was connected. Since my router cannot do this on it's own... I created a single line command that will ping the gateway IP address based upon knowing that my gateway will be my second hop (after my wifi router), tracerouting for 2 hops, pulling the last line of the traceroute output and grep'ing for just the IP address. To stop pinging, use . This works on linux and osx and, with the addition of cygwin tools or the win-gnu project... should work on windows as well. Show Sample Output


    0
    ping `traceroute -m 2 8.8.8.8 |tail -1|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"`
    andrewgearhart · 2015-03-25 19:55:54 74
  • 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
  • In the vein of "can you do it better", here is my take on using "ping" to emulate sleep in a DOS/BAT script. If one can use ping at all then the multicast address will be valid but will not respond. By doing only one ping (-n 1) and setting a timeout in milliseconds (-w 10000) you have a fairly accurate timer. This example gives about a 10 second sleep.


    -1
    ping -n 1 -w 10000 224.0.0.0
    DocGyver · 2009-08-26 02:25:07 9
  • Does one ping to a URL or host, and echo out just the response time. I use this on, with MRTG to monitor the connections to various hosts. Show Sample Output


    -1
    ping -c 1 www.google.com | /usr/bin/awk '{print $7}' | /usr/bin/awk 'NR > 1' | /usr/bin/awk 'NR < 2' | /usr/bin/awk -F"=" '{print $2}'
    ackers · 2010-12-15 08:50:52 4

  • -1
    for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done
    hackuracy · 2011-08-26 11:09:43 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
  • If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.


    -2
    for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done
    AlecSchueler · 2009-08-26 06:04:24 11
  • 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
  • On Linux and Mac systems (I have not tested with other Unix systems), the ping command will keep on pinging until the user interrupts it with Ctrl+C. On Windows system, ping will execute for a number of times then quit. The -c flag on Linux and Mac will make this happen


    -4
    ping -c 10 hostname
    haivu · 2009-03-04 06:14:52 6
  • 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
  • Say you need to ping every 5th IP address on your network .. this will give you a way of doing that. jot can also do counting ... like jot 4 1 2 3 4 download from http://oreilly.com/catalog/upt2/examples/#jot or fins athena-jot in rpm format Show Sample Output


    -5
    for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
    chinkshady · 2009-03-23 23:51:18 12
  • documents all active ips on a subnet and saves to txt file. Show Sample Output


    -9
    FOR /L %i IN (1,1,254) DO ping -n 1 10.254.254.%i | FIND /i "Reply">> c:\ipaddresses.txt
    barrytrujillo · 2010-06-29 21:02:21 3

  • -74
    ping www.facebook.com
    thuynnx · 2009-11-09 20:26:50 11
  •  < 1 2 3

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

Numerically sorted human readable disk usage
Provides numerically sorted human readable du output. I so wish there was just a du flag for this.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Split huge file into DVD+R size chunks for burning
Real DVD+R size is 4700372992 bytes, but I round down a little to be safe. To reconstitute use cat. "cat file.img.gz.aa file.img.gz.ab ..... > file.img.gz"

Find the package that installed a command

Delete all but the latest 5 files, ignoring directories

cat stdout of multiple commands
Concatenate the stdout of multiple commands.

Generates a TV noise alike output in the terminal
Generates a TV noise alike output in the terminal. Can be combined with https://www.commandlinefu.com/commands/view/9728/make-some-powerful-pink-noise

check open ports without netstat or lsof

Check command history, but avoid running it
!whatever will search your command history and execute the first command that matches 'whatever'. If you don't feel safe doing this put :p on the end to print without executing. Recommended when running as superuser.

Convert file type to unix utf-8
converts encoding of a file to unix utf-8 useful for data files that contain what would be usable ascii text but are encoded as mpeg or some other encoding that prevents you from doing common manipulations like 'sed'


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: