🐶🐶🐶
需要脚本获取本机ip地址
默认获取第二个网卡的IP地址
第一个 127.0.0.1 这个地址获取没有作用

string=`ip addr | grep  -w "inet" | sed -n "2, 2p"  | awk '{print $2}'`

自动获取本机ip,然后探测相同网段的ip信息。

 #!/bin/bash
 pName=$(rpm -qa | grep "nmap")
 if [ $? -eq 0 ]
 then
           echo "软件包nmap已经安装。"
 else
            yum  install nmap -y
fi
# 获取本机ip地址
string=`ip addr | grep  -w "inet" | sed -n "2, 2p"  | awk '{print $2}'`
str=`echo ${string} | cut -d "." -f 4`
ip=`echo  ${string/$str/}`
  # 探测与本机相同网段的ip
  nmap -sP ${ip}0/24 | grep "192" | cut -d " " -f 5 > ipfile
  echo "" > res
  for iplis  in `cat ipfile`
  do
     echo "$iplis 的信息" >>  res
     nmap -p1-1024  $iplis | egrep -v "Starting |Nmap|Host|Not" >> res
     echo "已探测 $iplis 的简略信息 "
  done

探测IP地址

#! /bin/bash
# 参数是网卡  名称
#例如:  ./test.sh  ens33
if [ "$#" -ne 1 ];then
	echo "usage -- ./arp1.sh [interface]"
	echo "Example -- ./arp1.sh eth1"
	exit
fi
echo "" > mac_ip.text
interface=$1
ipprefix=`ifconfig $interface|grep "netmask"|awk '{print $2}'|cut -d '.' -f 1-3`
for addr in $(seq 1 1254);do
	info=$(arping -c 1 $ipprefix.$addr)
	if [ $? -eq 0 ];then
		mac=`echo $info | grep "from"|cut -d ' ' -f 10`
		ipaddr=`echo $info|grep "from"|cut -d ' ' -f 2`
		echo "$mac -- $ipaddr"
		echo "$mac -- $ipaddr" >> mac_ip.text
	else
		echo "当前扫描的第$addr 是非活动地址!!"
	fi
done