Posts tagged script

Ping Script

0

A few minutes ago I completed this little ping script,
for non initiated users.

It first pings the 192.168.1.1
then pings the 192.168.2.1
after that it pings the 8.8.8.8
and finally pings the www.google.com address

Why does it pings 1.1 and 2.1 ?

Because my friend wanted to use it in different areas, ( he his not familiar with the shell ) for example at work 1.1 and home 2.1.

Why does it pings 8.8.8.8 and google.com ?

Similar as above  8.8.8.8 is the DNS of google .. and  google.com is just reaching the web

How does it work ? :

Execute the script.sh and it will print out  5 pings to 1.1  and write the result in GREEN / RED and then 5 pings to 2.1 and the result in GREEN / RED
and so one.

The script :

#!/bin/sh
GREEN="\\033[1;32m"
NORMAL="\\033[0;39m"
RED="\\033[1;31m"
clear
####################### 1.1 ################
ping -c 5 192.168.1.1
if [ ! "$?" -eq 0 ]; then
echo -e "$RED" "ping 1.1 failed" "$NORMAL"
else
echo -e "$GREEN"  "ping 1.1 passed" "$NORMAL"
fi
########################## 2.1 ##############
ping -c 5 192.168.2.1
if [ ! "$?" -eq 0 ]; then
echo -e "$RED"  "ping 2.1 failed" "$NORMAL"
else
echo -e "$GREEN" "ping 2.1 passed" "$NORMAL"
fi
########################## 8.8 ##############
ping -c 5 8.8.8.8
if [ ! "$?" -eq 0 ]; then
echo-e "$RED" "ping 8.8 failed" "$NORMAL"
else
echo -e "$GREEN" "ping 8.8 passed" "$NORMAL"
fi
########################## GOOGLE ##############
ping -c 5 www.google.com
if [ ! "$?" -eq 0 ]; then
echo -e "$RED" "ping google failed" "$NORMAL"
else
echo -e "$GREEN" "ping google passed" "$NORMAL"
fi

So have fun ;)

How to know my public ip address with bash

0

this is a little bash script to know your public ip address
this was tested on snow leopard and it works well
it can be use also on linux … i tested it on my ubuntu and it’s also good working

#!/bin/bash

wget http://www.monip.org/ 2> /dev/null
echo "The public ip is :"
perl -ne 'print "$1\n" if m/((\d{1,3}\.){3}\d{1,3})/' < index.html
rm index.html

You can use it when you’r behind a nat … it’s actually good working ( based on http request’s)

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Go to Top