0% found this document useful (0 votes)
13 views2 pages

Day 2

This document contains information about shell scripting and Linux architecture. It discusses the different types of shells in Linux like Bourne, C, Korn, and Bash shells. It also covers relational operators and predefined variables in Linux like $$, $0, and $?. The document provides examples of shell scripts for pinging an IP to determine the operating system, checking network connectivity, and using netcat for port scanning and grabbing server banners.

Uploaded by

arhhussain.786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Day 2

This document contains information about shell scripting and Linux architecture. It discusses the different types of shells in Linux like Bourne, C, Korn, and Bash shells. It also covers relational operators and predefined variables in Linux like $$, $0, and $?. The document provides examples of shell scripts for pinging an IP to determine the operating system, checking network connectivity, and using netcat for port scanning and grabbing server banners.

Uploaded by

arhhussain.786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Day 2

Sunday, January 28, 2024 9:05 AM

Shell Scripting Architecture of Linux

Types of shell in Linux


➢ Bourne shell
➢ C-Shell
➢ Korn shell
➢ Bourne again shell
➢ Z-shell

Relational operators Predefined Variables in Linux


➢ -eq - equals to - = ➢ Echo $$ -> process id of a shell
➢ -ne - not equals to - != ➢ Echo $0 - > current shell
➢ -lt - less than - < ➢ Echo $? -> exit status of last command
➢ -gt - greater than - > ➢ Echo $! -> process id of background process
➢ -le - less than equals to - <=
➢ -ge - greater than equals to - >=

➢ 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

New Section 1 Page 1


➢ 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
• Open remote connections echo -e "\n Internet is working fine"
• Read/Write data across the network else
• Network debugging echo "Internet connectivity is down"
• Simple TCP Proxies fi

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

New Section 1 Page 2

You might also like