LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 982|回复: 1

一个网吧中都做了物理地址与ip地址的帮定,请问用什么方法可以查出这台机器的ip

[复制链接]
发表于 2006-8-25 10:40:20 | 显示全部楼层 |阅读模式
也就是说在这个网吧中这台机器只有用一个固定的ip才可以上网,但只知道他是192.168.1.x中的一个,但不知到在这255个地址中哪个才是,我只有一个地址一个地址的试。谁能帮写个脚本当机器自动试出来哪个地址是对的?
发表于 2006-8-25 12:12:57 | 显示全部楼层
  1. for i in 192.168.1.{1..254}; do
  2.       if ! ping -c2 $i 2>/dev/null 1>/dev/null; then
  3.            ifconfig eth0 $i netmask 255.255.255.0 broadcast 192.168.1.255
  4.            route add default gw xxxx
  5.            if ping -c2 www.google.com; then
  6.                    echo $i
  7.                    break
  8.            else
  9.                    route del default
  10.            fi
  11.      fi
  12. done
复制代码
replace the default gw with your gw ip. Also, instead of using ifconfig and route, you can use ip cmd suite.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表