Can I reach it? Small Script for Network Connectivity Test

I made this script so I can replicate a network connection test to some host. It’s really small but it works in all the cases and has some nice features as internal and external IP detection. It works in Linux, ideal for a pentest using Backtrack.

Here is the Bash code.

#!/bin/bash
# Script by Adrian Puente Z..
# Powered by Hackarandas www.hackarandas.com
# Licensed by GNU GPLv3
# http://www.gnu.org/licenses/gpl-3.0.txt

[ `id -u` -ne 0 ] && echo "Only root can do that! sudoing…"
if [ "$EUID" != 0 ]; then sudo `which $0` $@; exit; fi

[ $# -eq 0 ] && echo  "Syntax: `basename $0` <host>" && exit 0

# Setting the host from the first argument.
HOST=$1
# Maximun hops for traceroute.
HOPS=15
# Maximun packet for ping.
PCOUNT=3

IFACE=`route -vn | grep UG | sed ‘s/\ \ */\ /g’ | cut -d‘ ‘ -f8`
INTIP=`ifconfig ${IFACE} | grep "inet addr" | tr ‘ ‘ ‘:’ | cut -d‘:’ -f13`

# Choose the method you like most.
#EXTIP=`lynxsource http://www.whatismyip.org`
#EXTIP=`wget -q http://www.whatismyip.org -O-`
EXTIP=`curl -q http://www.whatismyip.org 2>/dev/null`

echo "— Internal IP: ${INTIP} —"
echo "— External IP: ${EXTIP} —"
echo -e "\n— Pinging…\n"
ping -c ${PCOUNT} ${HOST}
echo -e "\n— Doing traceroute…\n"
traceroute -m ${HOPS} ${HOST}
echo -e "\n— Checking open ports…\n"
nmap -sSV -PN ${HOST}
echo -e "\n— Test finished…"

You can change the parameters to fit your needs.

Here is an example.

      –.^       (ch0ks@xipe)*(18:30:27)*(bin)      ^.–
-=:)> checkconnection.sh www.google.com
Only root can do that! sudoing…
— Internal IP: 192.168.11.5
— External IP: A.B.C.D

— Pinging…

PING www.l.google.com (74.125.95.106) 56(84) bytes of data.
64 bytes from iw-in-f106.1e100.net (74.125.95.106): icmp_seq=1 ttl=51 time=67.2 ms
64 bytes from iw-in-f106.1e100.net (74.125.95.106): icmp_seq=2 ttl=51 time=65.8 ms
64 bytes from iw-in-f106.1e100.net (74.125.95.106): icmp_seq=3 ttl=51 time=66.3 ms

— www.l.google.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 65.895/66.490/67.223/0.626 ms

— Making traceroute…

traceroute to www.google.com (74.125.95.103), 15 hops max, 60 byte packets
 1  leviatan (192.168.11.250)  1.385 ms  1.465 ms  1.492 ms
 2  201.159.131.205 (A.B.C.D)  5.463 ms  5.511 ms  5.519 ms
 3  192.168.1.98 (192.168.1.98)  5.648 ms  5.710 ms  5.970 ms
 4  customer-58.xertix.com (201.159.136.58)  6.000 ms  6.067 ms  6.208 ms
 5  na-200-78-191-129.static.avantel.net.mx (200.78.191.129)  8.204 ms  8.264 ms  8.456 ms
 6  dial-200-39-225-125.zone-1.ip.dial.net.mx (200.39.225.125)  8.617 ms  6.470 ms  6.654 ms
 7  pos1-0.cr02.mca01.pccwbtn.net (63.218.161.69)  20.646 ms  20.614 ms  20.039 ms
 8  TenGE12-1.br02.dal01.pccwbtn.net (63.218.22.82)  303.761 ms * *
 9  google.tenge11-4.br02.dal01.pccwbtn.net (63.218.23.118)  33.544 ms  34.331 ms  34.501 ms
10  72.14.233.85 (72.14.233.85)  61.329 ms 72.14.233.77 (72.14.233.77)  61.388 ms  61.520 ms
11  216.239.47.121 (216.239.47.121)  69.114 ms  69.800 ms  69.511 ms
12  209.85.253.173 (209.85.253.173)  68.657 ms 209.85.255.223 (209.85.255.223)  67.482 ms 209.85.253.173 (209.85.253.173)  68.568 ms
13  209.85.241.29 (209.85.241.29)  66.212 ms  66.150 ms  66.263 ms
14  iw-in-f103.1e100.net (74.125.95.103)  65.803 ms  65.757 ms  65.991 ms

— Checking open ports…

Starting Nmap 5.00 ( http://nmap.org ) at 2010-08-20 18:31 CDT
Warning: Hostname www.google.com resolves to 6 IPs. Using 74.125.95.104.
Interesting ports on iw-in-f104.1e100.net (74.125.95.104):
Not shown: 996 filtered ports
PORT    STATE  SERVICE  VERSION
21/tcp  open   ftp?
80/tcp  open   http     Google httpd 2.0 (GFE)
113/tcp closed auth
443/tcp open   ssl/http Google httpd 2.0 (GFE)
Service Info: OS: Linux

Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 127.81 seconds

— Test finished…

I hope you liked and helped. You can also visit other scripts and projects I have here. And please, leave your comments.

Adrián Puente Z.

, , , , ,

Share