ping探测在线主机
一.实验要求:
1.对于给定范围的ip地址进行主机在线测试
2.ping测试结果保存在/tmp/ping目录下以时间戳为文件名的文件里,以便后续查看
二.实验过程:
#!/bin/env/ bash
#
#variable declaration
declare -a start_arr
declare -a end_arr
#define function
#IP address initialization
initial_fun(){
read -p "Initial Address:" host_start
read -p "End Address:" host_end
echo -e "Your test segment is : \033[31m${host_start} ~ ${host_end}\033[0m"
}
#Input validation
confirm_fun(){
read -p "Confirm(y);Exit(q);Re-Enter(r): " ack
ack=${ack:="y"}
while [ $ack != "y" -a $ack != "q" -a $ack != "r" ];do
read -p "Confirm(y);Exit(q);Re-Enter(r):" ack
done
}
#IP segmentation
Ip_field(){
local i
for ((i=1;i<=4;i++));do
start_arr[$[i-1]]=`echo $host_start | cut -d. -f $i`
end_arr[$[i-1]]=`echo $host_end | cut -d. -f $i`
done
}
#C class test
Cping_fun(){
local cnet=$1
local i=$2
local j=$3
while [ $i -le $j ];do
if ping -W 1 -c 1 $cnet.$i &> /dev/null;then
echo "$cnet.$i is up." | tee -a /tmp/ping/`date +%F-%H\:%M`.ping
else
echo "$cnet.$i is down."
fi
trap 'exit 1' INT
let i++
done
}
#B class test
Bping_fun(){
local bnet=$1
local i=`echo $2 | cut -d. -f1`
local I=`echo $2 | cut -d. -f2`
local j=`echo $3 | cut -d. -f1`
local J=`echo $3 | cut -d. -f2`
if [ $i -eq $j ];then
Cping_fun $bnet.$i $I $J
else
while [ $i -le $j ];do
Cping_fun $bnet.$i 0 254
let i++
done
fi
}
#main
cat << EOF
Host detetion address vaild range as follows:
B)| 128.0.0.0 ~~ 191.255.255.255
C)| 192.0.0.0 ~~ 223.255.255.255
Please enter your initial address and end address segment detection
such as:192.168.1.1 192.168.1.99
EOF
[ ! -d /tmp/ping ] && mkdir /tmp/ping
initial_fun
confirm_fun
until [ $ack == "y" ];do
if [ $ack == "q" ];then
exit 1
else
initial_fun
confirm_fun
fi
done
[ $ack == "y" ]&& echo "Test is starting..."
Ip_field
if [ ${start_arr[0]} -ge 192 -a ${start_arr[0]} -le 223 ];then
net_addr=${start_arr[0]}.${start_arr[1]}.${start_arr[2]}
flag_start=${start_arr[3]}
flag_end=${end_arr[3]}
Cping_fun $net_addr $flag_start $flag_end
elif [ ${start_arr[0]} -ge 128 -a ${start_arr[0]} -le 191 ];then
net_addr=${start_arr[0]}.${start_arr[1]}
flag_start=${start_arr[2]}.${start_arr[3]}
flag_end=${end_arr[2]}.${end_arr[3]}
Bping_fun $net_addr $flag_start $flag_end
else
echo "Sorry,the detection of such addresses is not supported for the time being."
fi
三.实验总结:递推
四.实验思考:
1.如何进行A类地址测试
2.如何解决超址范围的ip引出的bug
3.能不能给定三个参数,起始ip,结束ip,子网掩码编写个更优的测试脚本
ping探测在线主机的更多相关文章
- sh 测试网段在线主机
yum install nmap nmap -sP 192.168.21.1/24 查看网段在线主机 grep -vwf file1 file2 文件内容比较 #!/bin/bash # day=` ...
- 求局域网内所有在线主机的ip
在一个局域网内,已知其中一台主机的ip为192.,子网掩码为255.,求所有其他在线主机的ip. shell 编码实现 #!/bin/bash netWorkIP=. ) do $netWorkIP$ ...
- 批量ping 检测linux主机是否可以通
批量ping 检测linux主机是否可以通 # 1.配置列表 [root@db137 liweiwie]# cat /home/dbatlbb/script/liweiwie/ping_ip.txt ...
- 解决ping不通win7主机
之前在路由器上ping笔记本发现ping不通,但是笔记本ping路由器通,也没多想.今天想起来可能是win7的防火墙作怪,以前上课虚拟机好像也是ping不通宿主机,但是宿主机能ping通虚拟机. 简单 ...
- 连续4个小时ping不通远端主机,则本机关机
#!/bin/bash #连续4个小时ping不通远端主机,则本机关机. begin_time=$(date "+%s") while true;do sleep 2 ping - ...
- VMware的linux虚拟机配置ip后无法ping通宿主机
VMware的linux虚拟机配置ip(使用eth0)后无法ping通宿主机,同样宿主机无法ping通linux虚拟机. 可能原因:linux虚拟机使用的网卡,与本机使用的网卡不同,配置成与本机一致的 ...
- 运维派 企业面试题4&5 创建10个 用户 ; ping探测主机是否在线
Linux运维必会的实战编程笔试题(19题) 企业面试题4: 批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串). #!/bin/bash # ;i<=; ...
- ping探测与Nmap扫描
一.实验目的 学习信息收集的一般步骤 学会使用ping命令 利用Nmap工具进行信息搜集 二.实验环境 系统环境:一台windows7系统.一台XP系统.一台kali系统 软件环境:安装Wiresha ...
- cnentos中进行bond网卡配置,一切配置无问题,就是ping不通宿主机
服务器网口绑定 1. ifcfg-bond0 DEVICE=bond0 ONBOOT=yes IPADDR=192.168.100.64 NETMASK=255.255.255.0 2. ...
随机推荐
- PostgreSQL学习(2)-- mvcc
1.PG事务隔离级别 在数据库中,并发的操作进行读写数据时,则会遇到脏读.不可重复读.幻读.串行化异常等问题. 数据库事务的特性: 原子性(Atomicity):事务作为一个整体被执行,包含在其中的对 ...
- 【数学 BSGS】bzoj2242: [SDOI2011]计算器
数论的板子集合…… Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最 ...
- python入门:UTF-8转换成GBK编码
#!/usr/bin/env python # -*- coding:utf-8 -*- #UTF-8转换成GBK编码 #temp(临时雇员,译音:泰坡) #decode(编码,译音:迪口德) #en ...
- 【转】centos中service命令与/etc/init.d的关系以及centos7的变化
centos中service命令与/etc/init.d的关系 service httpd start 其实是启动了存放在/etc/init.d目录下的脚本. 但是centos7的服务管理改规则了.C ...
- verilog $fopen 函数的小缺陷
system task $fopen 的argument 为1.文件名字(可以包含具体的文件路径但是注意用)2.打开方式比如"r"."w"."a&qu ...
- LeetCode(274)H-Index
题目 Given an array of citations (each citation is a non-negative integer) of a researcher, write a fu ...
- Developing for nRF52810(转载)
Table of Contents Introduction Hardware emulation of nRF52810 Limitations Software emulation of nRF5 ...
- 库函数的使用:POJ1488-TEX Quotes(getline()的使用)
TEX Quotes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9385 Description TEX is a type ...
- poj 3107 Godfather(树的重心)
Godfather Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7885 Accepted: 2786 Descrip ...
- bzoj3039 joyoi1939 玉蟾宫 悬线法
悬线法 #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...