IP探测工具

#!/bin/bash

# 定义要探测的IP地址范围
start_ip="192.168.0.1"
end_ip="192.168.0.255"

# 将IP地址转换为整数
ip_to_int() {
    local IFS="."
    read -r ip1 ip2 ip3 ip4 <<< "$1"
    echo $((ip1 * 256 * 256 * 256 + ip2 * 256 * 256 + ip3 * 256 + ip4))
}

# 将整数转换为IP地址
int_to_ip() {
    local ip=$1
    echo "$((ip / 256 / 256 / 256)).$(((ip / 256 / 256) % 256)).$(((ip / 256) % 256)).$((ip % 256))"
}

# 循环遍历IP地址范围
current_ip=$(ip_to_int "$start_ip")
end_ip=$(ip_to_int "$end_ip")

while true; do
    ip=$(int_to_ip $current_ip)
    
    # 使用ping命令探测IP是否可达
    ping -c 1 -W 1 $ip > /dev/null
    
    # 检查ping命令的返回值,如果返回值为0,则表示IP可达
    if [ $? -eq 0 ]; then
        echo "IP地址 $ip 可达"
    else
        echo "IP地址 $ip 不可达"
    fi
    
    # 判断是否已经到达结束IP地址
    if [ $current_ip -eq $end_ip ]; then
        break
    fi
    
    # 递增IP地址
    current_ip=$((current_ip + 1))
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值