Sometimes you need to configure a static IP address for the server or something and you do not know that the IP address is not occupied. In this case, it is very convenient to use this script.
# Cat arping
#! /Bin/bash
IPaddr = 192.168.0.
IPFILE =/root/arping.txt
UPIPaddr =/tmp/ipup.txt
DOWNIPaddr =/tmp/ipdown.txt
> $ IPFILE
Touch $ DOWNIPaddr
Touch $ UPIPaddr
Touch $ IPFILE
For IP in {1 .. 254}
Do
Arping-c 1 $ IPaddr $ IP >>$ IPFILE
Done
Echo UPIPADDR
Echo "ipaddr mac "; cat $ IPFILE | grep reply | awk '{print $4 "" $5}' | awk-F "[" '{print $1 "" $2}' | awk- F "]" '{print $1 "" $2}' | column-t> $ UPIPaddr
Echo DOWNIPADDR
IPTMP =/tmp/ip.txt
IPTMP2 =/tmp/ip2.txt
Grep-v ^ '[S | R]' $ IPFILE | awk-FARPING '{print $2}' | awk-Ffrom '{print $1}' | column-t> $ IPTMP
Grep-v ^ '[S | R]' $ IPFILE | awk-F "Unicast reply from" '{print $2}' | awk '{print $1}' | uniq -c | awk '{print $2}' | uniq-c | awk '{print $2}' | column-t> $ IPTMP2
Cat $ IPTMP $ IPTMP2 | sort-t "."-k4, 4n | uniq-u> $ DOWNIPaddr
VL = 'wc-l $ UPIPaddr | awk '{print $1 }''
VL2 = 'wc-l $ DOWNIPaddr | awk' {print $1 }''
Cat $ UPIPaddr
Echo currently has $ VL hosts active
Cat $ DOWNIPaddr | paste-s
Echo currently has $ VL2 available IP addresses
For ease of use, directly list the IP address and MAC address of the active host, and print out unused IP addresses. Sometimes it is very convenient to use.
NETIP = 192.168.0.0/24
Echo IPaddr "" status; nmap-sP $ NETIP | grep up | awk '{print $3}' | awk-F "(" '{print $2}' | awk-F ") "'{print $1" up "}' | column-t
This article is from the "Technical Exchange" blog