Take a example of a network where you need to find how many IP addresses are available [ it work if ping allowed ]
- ping any IP.
- ping 192.168.1.2
- ping with specific packets. -c = count and 4 = number of packets
- ping 192.168.1.2 -c 4
- save the ping output in ip.txt file.
- ping 192.168.1.2 -c 4 > ip.txt
- Opening file with the specific output of packets, suppose where ping is received you get 64 bytes as an output but where no ping happens no bytes reflects in output. so we need only those IPs which we are able to ping
- cat ip.txt | grep "64 bytes"
- cat = print content of file.
- | (pipe) = to add another command in single line
- grep = to filter something from the huge content. 64 bytes are present in the ip.txt file.
- narrow down more filter. Now we have full sentence which is an output of ping, but we require only IP address
- cat ip.txt | grep "64 bytes" | cut -d " " -f 4
- cut -d " "= command to extract information on the basis of space available in the sentence.
- -f 4 = -f is a field, 4 is 4th field, which is an IP address.
- In this specific case : is also visible at the end of each IP address, with colon we will not to proceed further for eg: if we want to nmap scan each IP.
- cat ip.txt | grep "64 bytes" | cut -d " " -f 4 | tr -d ":"
- tr -d " :" = tr is translate -d delimiter and ":" is which we need to remove.
To go further:
- Above script - Explanation
- to run =
- give executable permission
- chmod 777 <<script name>>
- ./<<script name>> <<first 3 octets of IP address>>
- #!/bin/bash = to define it is a bash script.
- if [ "$1" == "" ] = if condition , $1 is a variable (first 3 octets of the ip address we need to give)
- for ip in `seq 1 254`; do = for loop starting from 1 to 254 range with a variable name ip,
- eg.
- 192.168.1 = given by user
- 1 ,2 ,3 ,4 = will be added by for loop
- 192.168.1.1, 192.168.1.2, 192.168.1.3, 192.168.1.4, 192.168.1.5 so on till 254
- ping -c 1 $1.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" &
- ping command with 1 packet , with user input in $1 variable, pipe( | , to add another command), to get 4th field of the command's output, and then eliminate : from the IP addresses
- & = used to do not let it go in infinite loop.
script is available.
#!/bin/bash
if [ "$1" == "" ]
then
echo "You forgot an IP address!"
echo "Syntax: ./ipsweep.sh 192.168.1"
else
for ip in `seq 1 254`; do
ping -c 1 $1.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" &
done
fi
- One Liner Bash script: -
- suppose you have ran above file (.ipsweep.sh) like mentioned below. taking output in the file
- ./ipsweep.sh 192.168.1 > ip.txt
- Now we can execute this file as below.
- sudo su - : "sudo su -" means invoking root user with new environment, not to disturb root user's existing environment.
- one liner command is: -
- for ip in $(cat ip.txt); do nmap -p 80 -T4 $ip& done
- for is a loop
- ip is for loop's varibale
- #(cat ip.txt) - to get a file as an input for for loop.
- ; (semicolon) is to finish the loop statement.
- do is an instruction to execute.
- nmap -p 80 -Pn -sV $ip& done - is a commands ( $ip is an ip variable done).



batuin_kiDes Moines Christina Evans https://wakelet.com/wake/bypCZVv0KJaEksAiGa09B
ReplyDeletediafurnsifer
Wstupra0perf-da Alicia Green Norton Security
ReplyDeleteSoftware
Winamp Pro
kolsdolocom