目录
判断两个IP是否在同一网段
判断IP地址是否在某一个ip段内
IP网络地址和广播地址计算
判断两个网段是否存在包含与被包含的关系
计算可用IP地址范围
附录:
如何判断两个IP是否在同一网段原理
判断脚本
(转自:http://t.csdn.cn/3UmL3)
原理
ip和掩码做与计算。如果结果相同,则证明两个ip在同一个网段
#!/bin/bashIPPattern&#61;&#39;^(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>$&#39;function check_ip_valide()
{IP&#61;"$1"for special_ip in ${special_ips[&#64;]}dolocal ret&#61;$(echo $IP | grep ${special_ip})if [ -n "$ret" ];thenreturn 1fidoneif [[ "${IP}" &#61;~ ${IPPattern} ]]; thenreturn 0elsereturn 1fi}
function calc_ip_net()
{sip&#61;"$1"snetmask&#61;"$2"check_ip_valide "$sip"if [ $? -ne 0 ];then echo "";return 1;filocal ipFIELD1&#61;$(echo "$sip" |cut -d. -f1)local ipFIELD2&#61;$(echo "$sip" |cut -d. -f2)local ipFIELD3&#61;$(echo "$sip" |cut -d. -f3)local ipFIELD4&#61;$(echo "$sip" |cut -d. -f4)local netmaskFIELD1&#61;$(echo "$snetmask" |cut -d. -f1)local netmaskFIELD2&#61;$(echo "$snetmask" |cut -d. -f2)local netmaskFIELD3&#61;$(echo "$snetmask" |cut -d. -f3)local netmaskFIELD4&#61;$(echo "$snetmask" |cut -d. -f4)local tmpret1&#61;$[$ipFIELD1&$netmaskFIELD1]local tmpret2&#61;$[$ipFIELD2&$netmaskFIELD2]local tmpret3&#61;$[$ipFIELD3&$netmaskFIELD3]local tmpret4&#61;$[$ipFIELD4&$netmaskFIELD4]echo "$tmpret1.$tmpret2.$tmpret3.$tmpret4"
}
tmpip1&#61;$(calc_ip_net "$1" "$3")
tmpip2&#61;$(calc_ip_net "$2" "$3")if [ "$tmpip1" !&#61; "$tmpip2" ];thenecho "no"
elseecho "same"
fi
实验结果
&#xff08;摘自&#xff1a;https://blog.csdn.net/m0_46171781/article/details/124489645&#xff09;
方法1&#xff1a;利用&#xff08;依赖&#xff09;ipcalc
#!/bin/bash
IP&#61;$1
if [ -z $IP ]
thenecho -e "\e[31;42m sh ipcalc.sh IP \e[0m"exit
fi
while read MASK
domax&#61;&#96;/usr/bin/ipcalc -mbn $MASK|grep &#39;BROADCAST&#61;&#39;|awk -F &#39;BROADCAST&#61;&#39; &#39;{print $2}&#39;&#96;min&#61;&#96;/usr/bin/ipcalc -mbn $MASK|grep &#39;NETWORK&#61;&#39;|awk -F &#39;NETWORK&#61;&#39; &#39;{print $2}&#39;&#96;MIN&#61;&#96;echo $min|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;MAX&#61;&#96;echo $max|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;IPvalue&#61;&#96;echo $IP|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;if [ "$IPvalue" -ge "$MIN" ] && [ "$IPvalue" -le "$MAX" ]thenecho "$IP"exitfi
done
cat > /usr/local/bin/judge_ip <<&#39;EOF&#39;
#!/bin/bash
MASK&#61;$2
IP&#61;$1
max&#61;&#96;/usr/bin/ipcalc -mbn $MASK|grep &#39;BROADCAST&#61;&#39;|awk -F &#39;BROADCAST&#61;&#39; &#39;{print $2}&#39;&#96;
min&#61;&#96;/usr/bin/ipcalc -mbn $MASK|grep &#39;NETWORK&#61;&#39;|awk -F &#39;NETWORK&#61;&#39; &#39;{print $2}&#39;&#96;
MIN&#61;&#96;echo $min|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;
MAX&#61;&#96;echo $max|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;
IPvalue&#61;&#96;echo $IP|awk -F"." &#39;{printf"%.0f\n",$1*256*256*256&#43;$2*256*256&#43;$3*256&#43;$4}&#39;&#96;
if [ "$IPvalue" -ge "$MIN" ] && [ "$IPvalue" -le "$MAX" ]
then
echo "$IP"
exit
fi
EOF
chmod 777 /usr/local/bin/judge_ipjudge_ip 192.168.10.11 192.168.10.0/24
方法2&#xff1a;
方法1中用ipcalc计算出 网络地址&#xff08;min&#xff09;和广播地址&#xff08;max&#xff09;&#xff0c;但是由于某些机器上没有安装有ipcalc&#xff0c;所以可以用下面《IP网络地址和广播地址计算》章节的方法计算出min和max。
&#xff08;摘自&#xff1a;https://www.itdaan.com/blog/2016/01/26/41c02cab944c228bfb81a1dc1f999aa0.html&#xff09;
#!/bin/bash
IPPattern&#61;"(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
maskPattern&#61;"[1-9]|[12][0-9]|3[01]"while :
doecho -e -n "Please input a legal IP address [such as 192.168.1.1/16]: "read userInputIPMask&#61;&#96;echo $userInput | egrep "$IPPattern/$maskPattern"&#96; #Such as 192.168.1.1/24if [ -z "$IPMask" ] ;thenecho "Please input the right format. [such as 192.168.1.1/1-31] "continuefiIPAddr&#61;&#96;echo $IPMask | cut -d/ -f1&#96;IPType[1]&#61;&#96;echo $IPAddr | cut -d. -f1&#96;IPType[2]&#61;&#96;echo $IPAddr | cut -d. -f2&#96;IPType[3]&#61;&#96;echo $IPAddr | cut -d. -f3&#96;IPType[4]&#61;&#96;echo $IPAddr | cut -d. -f4&#96;mask&#61;&#96;echo $IPMask | cut -d/ -f2&#96;echo "IP address is ${IPType[1]}*${IPType[2]}*${IPType[3]}*${IPType[4]} , Mask is $mask ."((IPHex[1]&#61;IPType[1]<<24))((IPHex[2]&#61;IPType[2]<<16))((IPHex[3]&#61;IPType[3]<<8))((IPHex[4]&#61;IPType[4]))#192 c0 ; 1 1 1((iph&#61;${IPHex[1]}&#43;${IPHex[2]}&#43;${IPHex[3]}&#43;${IPHex[4]}))#echo $iph#0xffffffff#declare -i strMask1&#61;4294967295declare -i strMask1&#61;0xffffffff#echo $strMask1((strMask1&#61;strMask1<<(32-mask) & 0xffffffff))#echo $strMask1((strMask2&#61;~strMask1))#echo $strMask2((networkAddr&#61;iph & strMask1))((bcastAddr&#61; (iph | strMask2) & 0xffffffff))#echo $networkAddr | awk &#39;{printf "%x\n",$0}&#39;#echo $bcastAddr | awk &#39;{printf "%x\n",$0}&#39;((IPHex[1]&#61;networkAddr>>24 & 0x000000ff))((IPHex[2]&#61;networkAddr>>16 & 0x000000ff))((IPHex[3]&#61;networkAddr>>8 & 0x000000ff))((IPHex[4]&#61;networkAddr & 0x000000ff))echo -e "Network Address : ${IPHex[1]}.${IPHex[2]}.${IPHex[3]}.${IPHex[4]}"((IPHex[1]&#61;bcastAddr>>24 & 0x000000ff))((IPHex[2]&#61;bcastAddr>>16 & 0x000000ff))((IPHex[3]&#61;bcastAddr>>8 & 0x000000ff))((IPHex[4]&#61;bcastAddr & 0x000000ff))echo -e "Broadcast Address : ${IPHex[1]}.${IPHex[2]}.${IPHex[3]}.${IPHex[4]}"
done
转:https://blog.51cto.com/qinlouke/2327303
设定两个网段&#xff1a;net1是192.168.10.0/24&#xff0c;net2是192.168.10.128/25。使用Shell脚本&#xff0c;判断是net1包含net2还是net2包含net1. 解题思路&#xff1a;
将两个网段全部转换为二进制&#xff0c;且不带字段分隔符&#xff08;即点号&#xff09;&#xff0c;取网络位。如果在net1的二进制字符串里面截取到了net2的二进制字符串&#xff0c;则net2包含net1.
#!/bin/bash
net1&#61;"192.168.10.0/24"
net2&#61;"192.168.10.128/25"
netID1D&#61;"&#96;echo $net1 | cut -d "/" -f 1&#96;"
netID2D&#61;"&#96;echo $net2 | cut -d "/" -f 1&#96;"
mask1&#61;"&#96;echo $net1 | cut -d "/" -f 2&#96;"
mask2&#61;"&#96;echo $net2 | cut -d "/" -f 2&#96;"
array1D[0]&#61;"&#96;echo $netID1D | awk -v FS&#61;"." &#39;{print $1}&#39;&#96;"
array1D[1]&#61;"&#96;echo $netID1D | awk -v FS&#61;"." &#39;{print $2}&#39;&#96;"
array1D[2]&#61;"&#96;echo $netID1D | awk -v FS&#61;"." &#39;{print $3}&#39;&#96;"
array1D[3]&#61;"&#96;echo $netID1D | awk -v FS&#61;"." &#39;{print $4}&#39;&#96;"
array2D[0]&#61;"&#96;echo $netID2D | awk -v FS&#61;"." &#39;{print $1}&#39;&#96;"
array2D[1]&#61;"&#96;echo $netID2D | awk -v FS&#61;"." &#39;{print $2}&#39;&#96;"
array2D[2]&#61;"&#96;echo $netID2D | awk -v FS&#61;"." &#39;{print $3}&#39;&#96;"
array2D[3]&#61;"&#96;echo $netID2D | awk -v FS&#61;"." &#39;{print $4}&#39;&#96;"array1B[0]&#61;"&#96;echo "obase&#61;2;${array1D[0]}" | bc&#96;"
array1B[1]&#61;"&#96;echo "obase&#61;2;${array1D[1]}" | bc&#96;"
array1B[2]&#61;"&#96;echo "obase&#61;2;${array1D[2]}" | bc&#96;"
array1B[3]&#61;"&#96;echo "obase&#61;2;${array1D[3]}" | bc&#96;"
array2B[0]&#61;"&#96;echo "obase&#61;2;${array2D[0]}" | bc&#96;"
array2B[1]&#61;"&#96;echo "obase&#61;2;${array2D[1]}" | bc&#96;"
array2B[2]&#61;"&#96;echo "obase&#61;2;${array2D[2]}" | bc&#96;"
array2B[3]&#61;"&#96;echo "obase&#61;2;${array2D[3]}" | bc&#96;"zeroArray&#61;(0 0 00 000 0000 00000 000000 0000000)
for ((i&#61;0;i<${#array1B[$i]};i&#43;&#43;))
dozeroNum&#61;$((8 - ${#array1B[$i]}))if [ $zeroNum -gt 0 ]thentestStr&#61;"&#96;awk -v zero&#61;"${zeroArray[$zeroNum]}" -v rawStr&#61;"${array1B[$i]}" &#39;BEGIN {printf "%s%s",zero,rawStr}&#39;&#96;"array1B[$i]&#61;$testStrfi
donefor ((i&#61;0;i<${#array2B[$i]};i&#43;&#43;))
dozeroNum&#61;$((8 - ${#array2B[$i]}))if [ $zeroNum -gt 0 ] thentestStr&#61;"&#96;awk -v zero&#61;"${zeroArray[$zeroNum]}" -v rawStr&#61;"${array2B[$i]}" &#39;BEGIN {printf "%s%s",zero,rawStr}&#39;&#96;"array2B[$i]&#61;$testStrfi
donenetID1B&#61;${array1B[0]}${array1B[1]}${array1B[2]}${array1B[3]}
netID2B&#61;${array2B[0]}${array2B[1]}${array2B[2]}${array2B[3]}
netID1BNo0&#61;"&#96;awk -v inNet&#61;"$netID1B" -v inMask&#61;"$mask1" &#39;BEGIN {print substr(inNet,1,inMask)}&#39;&#96;"
netID2BNo0&#61;"&#96;awk -v inNet&#61;"$netID2B" -v inMask&#61;"$mask2" &#39;BEGIN {print substr(inNet,1,inMask)}&#39;&#96;"
echo -e "net1十进制为:$net1\tnet1二进制为:$netID1BNo0"
echo -e "net2十进制为:$net2\tnet2二进制位:$netID2BNo0"
netVS1&#61;"&#96;awk -v inNet1&#61;"$netID1BNo0" -v inNet2&#61;"$netID2BNo0" &#39;BEGIN {print index(inNet1,inNet2)}&#39;&#96;"
netVS2&#61;"&#96;awk -v inNet2&#61;"$netID1BNo0" -v inNet1&#61;"$netID2BNo0" &#39;BEGIN {print index(inNet1,inNet2)}&#39;&#96;"
if [ $netVS1 -ne 0 ]thenecho "计算结果:$net2 包含 $net1"
fi
if [ $netVS2 -ne 0 ] thenecho "计算结果:$net1 包含 $net2"
fi
运行结果
[root&#64;localhost ~]# sh netCal.sh
net1十进制为:192.168.10.0/24 net1二进制为:110000001010100000001010
net2十进制为:192.168.10.128/25 net2二进制位:1100000010101000000010101
计算结果:192.168.10.0/24 包含 192.168.10.128/25
转自&#xff1a;https://blog.csdn.net/ledrsnet/article/details/115443242
输入&#xff1a; 输入IP网段&#xff0c;格式: xx.xx.xx.xx/[0-32]
输出&#xff1a;可用地址范围
思路&#xff1a;
ip与掩码拆分&#xff0c;健壮性判断
按位与&#xff0c;或者主机位置0&#xff0c;求出网络号
计算该网段可用地址范围。
效果&#xff1a;
[root&#64;centos8 commonshells]# ./calIpRange.sh 114.12.3.3/30
114.12.3.3/30该网段网络号为114.12.3.0
114.12.3.3/30该网段最小可用地址为114.12.3.1
114.12.3.3/30该网段最大可用地址为114.12.3.2
114.12.3.3/30该网段广播地址为114.12.3.3
————————————————
脚本&#xff1a;
#!/bin/bash
#########################################################
#Filename: calIpRange.sh
# Author: LiangDong
# Email: 395539184&#64;qq.com
# Date: 2021-04-04
# URL: https://github.com/ledrsnet
# Desc: 输入IP网段&#xff0c;输出可用地址范围
# 1.ip与掩码拆分&#xff0c;健壮性判断
# 2.按位与&#xff0c;求出网络号
# 3.计算该网段可用地址范围。
#
#########################################################set -eu# 1.ip掩码拆分并进行健壮性判断
E_NOARGS&#61;65
if [ -z "$1" ];thenecho "Usage:&#96;basename $0&#96; ip/mask"exit $E_NOARGS
fi
IP_MASK&#61;$1
IP&#61;&#96;echo $IP_MASK |sed -En &#39;s/^(.*)\/([0-9]{1,2})/\1/p&#39;&#96;
NET_MASK&#61;&#96;echo $IP_MASK |sed -En &#39;s/^(.*)\/([0-9]{1,2})/\2/p&#39;&#96;
#echo IP_MASK&#61;$IP_MASK
#echo IP&#61;$IP
#echo NET_MASK&#61;$NET_MASK
if [[ ! $IP &#61;~ ^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ ]];thenecho "Ip address $IP is invalid . Useage: ip/mask" exit 2
elif [ $NET_MASK -gt 32 -o $NET_MASK -lt 0 ];thenecho "netmask should be in 0-32,your input netmask is $NET_MASK; Useage: ip/mask"exit 3
elif [ $NET_MASK -eq 32 ];thenecho "主机位是32位&#xff0c;可用地址为$IP"exit 4
fi# 2.求出ip第几段前几位作运算
IP_SUB1&#61;&#96;echo $IP |cut -d. -f1&#96;
IP_SUB2&#61;&#96;echo $IP |cut -d. -f2&#96;
IP_SUB3&#61;&#96;echo $IP |cut -d. -f3&#96;#IP_SUB4&#61;&#96;echo $IP |cut -d. -f4&#96;
#IP_INDEX&#61;&#96;[ $[$NET_MASK/8&#43;1] -ge 5 ] && echo 4 || echo $[$NET_MASK/8&#43;1]&#96;
#echo IP_INDEX&#61;$IP_INDEX
#eval echo \$IP_SUB$IP_INDEXIP_INDEX&#61;&#96;echo $[$NET_MASK/8&#43;1]&#96;
IP_SUB&#61;&#96;echo $IP |cut -d. -f$IP_INDEX&#96;
IP_SUB_BINARY&#61;&#96;echo "obase&#61;2;$IP_SUB" |bc |xargs printf "%08d"&#96;
#echo IP_INDEX&#61;$IP_INDEX
#echo IP_SUB&#61;$IP_SUB
#echo IP_SUB_BINARY&#61;$IP_SUB_BINARY
IP_SUB_NET_BIT&#61;$[$NET_MASK%8]
IP_SUB_HOST_BIT&#61;$[8-$NET_MASK%8]#echo IP_SUB_NET_BIT&#61;$IP_SUB_NET_BIT
#echo IP_SUB_HOST_BIT&#61;$IP_SUB_HOST_BIT# 3.网络位不变&#xff0c;主机位全为0
AVAILABLE_MIN_IP&#61;$(echo $IP_SUB_BINARY|head -c${IP_SUB_NET_BIT} |xargs printf "ibase&#61;2;%s&#96;echo 00000000 |head -c${IP_SUB_HOST_BIT}&#96;\n"|bc)
#echo AVAILABLE_MIN_IP&#61;$AVAILABLE_MIN_IP# 与操作 生成连续重复的字符串有什么好办法没?
#R_NET_MASK&#61;
#R_HOST_MASK&#61;
#R_MASK&#61;
#for i in &#96;seq ${IP_SUB_NET_BIT}&#96;;do
# R_NET_MASK&#43;&#61;1
#done
#for i in &#96;seq ${IP_SUB_HOST_BIT}&#96;;do
# R_HOST_MASK&#43;&#61;0
#done
#R_MASK&#61;&#96;echo "ibase&#61;2;$R_NET_MASK$R_HOST_MASK"|bc&#96;
#echo R_MASK&#61;$R_MASK
#A_MIN_IP&#61;$[$IP_SUB&$R_MASK]
#echo A_MIN_IP&#61;$A_MIN_IP# 网络位不变&#xff0c;主机位全为1
AVAILABLE_MAX_IP&#61;$(echo $IP_SUB_BINARY|head -c${IP_SUB_NET_BIT} |xargs printf "ibase&#61;2;%s&#96;echo 11111111 |head -c${IP_SUB_HOST_BIT}&#96;\n"|bc)
#echo AVAILABLE_MAX_IP&#61;$AVAILABLE_MAX_IP# 4.输出可用地址范围
case $IP_INDEX in
1)echo "$IP_MASK该网段网络号为${AVAILABLE_MIN_IP}.0.0.0"echo "$IP_MASK该网段最小可用地址为${AVAILABLE_MIN_IP}.0.0.1"echo "$IP_MASK该网段最大可用地址为${AVAILABLE_MAX_IP}.255.255.254"echo "$IP_MASK该网段广播地址为${AVAILABLE_MAX_IP}.255.255.255";;
2)echo "$IP_MASK该网段网络号为${IP_SUB1}.${AVAILABLE_MIN_IP}.0.0"echo "$IP_MASK该网段最小可用地址为${IP_SUB1}.${AVAILABLE_MIN_IP}.0.1"echo "$IP_MASK该网段最大可用地址为${IP_SUB1}.${AVAILABLE_MAX_IP}.255.254"echo "$IP_MASK该网段广播地址为${IP_SUB1}.${AVAILABLE_MAX_IP}.255.255";;
3)echo "$IP_MASK该网段网络号为${IP_SUB1}.${IP_SUB2}.${AVAILABLE_MIN_IP}.0"echo "$IP_MASK该网段最小可用地址为${IP_SUB1}.${IP_SUB2}.${AVAILABLE_MIN_IP}.1"echo "$IP_MASK该网段最大可用地址为${IP_SUB1}.${IP_SUB2}.${AVAILABLE_MAX_IP}.254"echo "$IP_MASK该网段广播地址为${IP_SUB1}.${IP_SUB2}.${AVAILABLE_MAX_IP}.255";;
4)echo "$IP_MASK该网段网络号为${IP_SUB1}.${IP_SUB2}.${IP_SUB3}.${AVAILABLE_MIN_IP}"echo "$IP_MASK该网段最小可用地址为${IP_SUB1}.${IP_SUB2}.${IP_SUB3}.$[${AVAILABLE_MIN_IP}&#43;1]"echo "$IP_MASK该网段最大可用地址为${IP_SUB1}.${IP_SUB2}.${IP_SUB3}.$[${AVAILABLE_MAX_IP}-1]"echo "$IP_MASK该网段广播地址为${IP_SUB1}.${IP_SUB2}.${IP_SUB3}.${AVAILABLE_MAX_IP}";;
*)echo "Calculator Error Exception!"
esac
如何判断两个IP是否在同一网段
&#xff08;摘自&#xff1a;https://www.cnblogs.com/longshiyVip/p/4707106.html&#xff09;
下来举例说明&#xff0c;如何去判断A和B两个IP是否在同一网段。
A IP&#xff1a;202.194.128.9B IP&#xff1a;202.194.128.14子网掩码&#xff1a;255.255.255.0
1.把A和B的地址转换为二进制的
A:1100 1010.1100 0010.1000 0000.0000 1001B:1100 1010.1100 0010.1000 0000.0000 1101掩码 :1111 1111.1111 1111. 1111 1111 .0000 0000
2、要判断两个IP是否在同一网段&#xff0c;主要是看看他们的网络标识是否一样&#xff0c;其实一个IP的网络标识也就是他的IP和子网掩码AND之后的结——比如上面两个AND以后的结果如下&#xff1a;
A:11001010.1100 0010.1000 0000 .0000 0000 转化为十进制&#xff1a;202.194.128.0B:1100 1010.1100 0010.1000 0000.0000 0000 转化为十进制&#xff1a;202.194.128.0
这说明两个IP的网络标识相同&#xff0c;也就是说他们在同一子网。
3、有的时候我们还想知道&#xff0c;两个IP各自的主机标识&#xff0c;先将子网掩码取反&#xff0c;再和IP做AND.
A:1100 1010.1100 0010.1000 0000.0000 1001B:1100 1010.1100 0010.1000 0000.0000 1101掩码取反:0000 0000.0000 0000.0000 0000.1111 1111
AND 之后结果&#xff1a;
A&#xff1a;0000 0000.0000 0000.0000 0000.0000 1001 转化为十进制&#xff1a;9B&#xff1a;0000 0000.0000 0000.0000 0000.0000 1101 转化为十进制&#xff1a;14
也就是说A和B的主机标识为9和14
计算掩码PREFIX数值
255.255.255.192--->11111111.11111111.11111111.1100000-→26个bit.---》PREFIX&#61;26
255.255.255.0--->11111111.11111111.11111111.0000000--->24个bit.---》PREFIX&#61;24
还有更简单的&#xff1a;
执行 ip addr &#xff0c;对于的IP 就自己显示PREFIX&#xff1a;
[root&#64;ezdcc ~]# ipcalc -p 192.168.88.56 255.255.255.0
PREFIX&#61;24
[root&#64;ezdcc ~]# ipcalc -n 192.168.88.56 255.255.255.0
NETWORK&#61;192.168.88.0
[root&#64;ezdcc ~]# ipcalc -m -b -n 119.29.29.29/28
NETMASK&#61;255.255.255.240
BROADCAST&#61;119.29.29.31
NETWORK&#61;119.29.29.16
语法格式&#xff1a; ipcalc [参数] [IP地址]
常用参数&#xff1a;
-b | 由给定的IP地址和网络掩码计算出广播地址 |
-h | 显示给定IP地址所对应的主机名 |
-m | 由给定的IP地址计算器网络掩码 |
-p | 显示给定的掩码或IP地址的前缀 |
-n | 由给定的IP地址和网络掩码计算网络地址 |
-s | 安静模式&#xff0c;不显示任何错误信息 |
--help | 显示帮助信息 |
ifconfig|grep -w "100.96.192.13" -B 1|head -n 1|awk -F ":" &#39;{print $1}&#39;