Use shell to count IP addresses and MAC addresses in the LAN, as well as unused IP addresses.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.