win查询ip地址:
ipconfig
win查询主机名:
ipconfig/all
ubuntu查询ip地址:
ifconfig
ubuntu查询主机名:
hostname
这就是win的IP地址
这就是ubuntu的IP地址
在win上ping一下ubuntu:
ping 10.133.130.170
在ubuntu上ping一下win,前提是win的防火墙都关掉才能成功:
ping 10.133.147.219
都能ping通了之后,在ubuntu上创建一个shell
gedit test.sh
打开test.sh后,先按“i”进入插入模式,就可以写代码了
代码如下:
#!/bin/bash
i=1;
count=0;
while [ $i -lt 15 ]
do
ping -c2 -i0.3 -w1 172.20.10.$i &>/dev/null
#先ping一下,这里之所以是这个ip,因为当时的IP是172.20.10.3,掩码是255.255.255.240,自行修改
if [ $? -eq 0 ]
then
echo "172.20.10.$i is up"
ping -a -c2 172.20.10.$i #再ping一下输出连接时长
nbtscan 172.20.10.$i #输出一下连接到的主机的主机名
let count++;
else
echo "172.20.10.$i is down"
fi
let i++;
done
echo $count;
写完之后,先按Esc,再输入
:wq
回车
就保存退出了
然后在终端输入:
chmod +x hello.sh
再输入:
./test.sh
就会输出结果了。