Day 2
Day 2
➢ Write a code which takes domain or IP as an input then ➢ Checking the Connectivity:
pings it and gives expected OS on the basis of TTL value -> Ping 127.0.0.1 -> NIC is working fine
-> Check default gateway -> default gateway is working fine
#!/bin/bash -> Check 8.8.8.8 -> Internet is working fine
echo "Enter IP to ping"
read ip #!/bin/bash
ttl=`ping -c 1 $ip | grep -o 'ttl=[0-9][0-9]*' | cut -d "=" -f 2` echo "Checking connectivity !!!!!"
if [ $ttl == 64 ] echo "checking NIC....."
then a=`ping -c 1 127.0.0.1 | grep received | cut -d " " -f 4`
echo "Operating System is Linux" if [ $a == 1 ]
elif [ $ttl == 128 ] then
then echo -e "\n NIC is working fine"
echo "Operating System is Windows" else
elif [ $ttl == 254 ] echo "NIC is down"
then fi
echo "Operating System is CISCO IOS" echo "checking Default Gateway......."
else route=`route | grep default | cut -d " " -f 10`
echo "You are hitting a firewall !!!!!" b=`ping -c 1 $route | grep received | cut -d " " -f 4`
fi if [ $b == 1 ]
then
echo -e "\n Default Gateway is working fine"
else
echo "Default Gateway is down"
Banner Grabbing fi
➢ Netcat - Swiss Army Knife echo "Checking Internet connectivity......"
• Port scanning c=`ping -c 1 8.8.8.8 | grep received | cut -d " " -f 4`
• Port listening if [ $c == 1 ]
• Port redirection then
Modes of nc
Switches of Netcat ➢ Connect mode
➢ -l -> listen mode • Nc example.com 80
➢ -p -> specify port number ➢ Listen mode
➢ -v -> verbose mode • Nc -l 192.168.175.147 4444
➢ -z -> scans for open ports
➢ -w -> set a timeout for connections
➢ -q -> specifies the delay before closing the connection
Banner Grabber
#!/bin/bash
echo "Enter the name or IP"
read domain
echo "Enter port number"
cmd="HEAD/ HTTP/1.0"
read port
if [ $port == 80 ]
then
echo -e "$cmd \r \n" | ncat $domain 80
elif [ $port == 443 ]
then
echo -e "$cmd \r \n" | ncat $domain 443 --ssl
else
ncat $domain $port
fi