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

Maximum PNG compression with optipng, advpng, and advdef
optipng and advancecomp (for the the advpng and advdef tools) are the best FOSS tools for losslessly compressing PNGs. With the above tool chain, you can cut off as much as 20% off a PNG's file size.

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

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

Create a backdoor on a machine to allow remote connection to bash
My netcat (nc-1.84-10.fc6) doesn't have the -e option, so I have to do it like this. Of course, instead of bash, you can use any executable, including scripts.

Show OS release incl version.

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.'

whowatch: Linux and UNIX interactive, process and users monitoring tool
whowatch is a interactive, ncurses-based, process and users monitoring tool, which updates information in real time. This is a perfect tool for local and remote servers. It displays information about the users currently logged on to the machine, in real-time. Besides standard information (login name, tty, host, user's process), the type of the connection (ie. telnet or ssh) is shown. Display of users command line can be switch to tty idle time. Certain user can be selected and his processes tree may be viewed as well as tree of all system processes. Tree may be displayed with additional column that shows owner of each process. In the process tree mode SIGINT and SIGKILL signals can be sent to the selected process. Killing processes is just as simple and fun as deleting lines on the screen.

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

Show crontabs for all users
added echo "### Crontabs for $user ####"; to make clear whose crontab is listed.

Replace spaces in filenames with underscores


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: