判断主机ip是否在线

脚本

#!/bin/bash
for ip in `seq 1 255`
do
ping -c 1 192.168.0.$ip >/dev/null 2>&1
if [ $? -eq 0 ];then
echo "192.168.0.$ip up"
else
echo "192.168.0.$ip down"
fi
done
#!/bin/bash
for ip in 192.168.0.{1..255}
do
ping -c 1 $ip &> /dev/null
if [ $? -eq 0 ];then
echo "$ip up"
else
echo "$ip down"
fi
done
#!/bin/bash
for ip in `seq 1 255`
do
ping -c 1 192.168.255.$ip &> /dev/null && echo "192.168.255.$ip up" || echo "192.168.255.$ip down"
done

命令,速度很快,比脚本好用多了

[root@master] ~$ nmap -sn 192.168.255.0/24

Starting Nmap 6.40 ( http://nmap.org ) at 2018-04-17 14:51 CST
Nmap scan report for 192.168.255.1
Host is up (0.0013s latency).
。。。。。
Nmap done: 256 IP addresses (9 hosts up) scanned in 1.49 seconds
阅读更多

如何判断指定ip主机 是否在线

01-13

如题,我以实现以ip获得mac了rn但是如何获得其他信息?比如主机名等等.是否在线 如何判断?rn望高手们指点rnrn以IP获得mac地址代码不敢独享,小弟拿出来给大家共享rn[code=VB.NET]rnImports System.DiagnosticsrnImports System.ThreadingrnPublic Class myThreadrn Private ip As Stringrn Private cnt As Integerrn Public ff As DataGridViewrn Public Sub setinfo(ByVal tip As String, ByVal tcnt As Integer)rn Me.ip = tiprn Me.cnt = tcntrn Dim myth As Thread = New Thread(New ThreadStart(AddressOf vs_ipmac))rn myth.Start()rn End Subrn Private Sub vs_ipmac()rn ff.Rows(cnt).Cells(3).Value = "扫描中..."rn Dim str1 As String = String.Emptyrn Tryrn Dim str2 As String = String.Emptyrn Dim info1 As ProcessStartInfo = New ProcessStartInfo()rn Dim process1 As Process = New Process()rn info1.FileName = "nbtstat"rn info1.RedirectStandardInput = Falsern info1.RedirectStandardOutput = Truern info1.Arguments = "-A " + iprn info1.UseShellExecute = Falsern info1.CreateNoWindow = Truern process1 = Process.Start(info1)rn Dim num1 As Integer = -1rnrn While (num1 <= -1)rn num1 = str2.Trim().ToLower().IndexOf("mac address", 0)rn If (num1 > -1) Thenrn Exit Whilern End Ifrnrn str2 = process1.StandardOutput.ReadLine()rn process1.WaitForExit()rn str1 = str2.Trim()rn End Whilern Catch ex As Exceptionrn 'Throw exrn End Tryrn If str1 <> "" Thenrn If LCase(ff.Rows(cnt).Cells(4).Value.ToString) <> LCase(Right(str1, 17)) Thenrn ff.Rows(cnt).Cells(2).Value = My.Resources.flag_yellowrn Elsern ff.Rows(cnt).Cells(2).Value = My.Resources.flag_greenrn End Ifrn ff.Rows(cnt).Cells(3).Value = Right(str1, 17)rn Elsern ff.Rows(cnt).Cells(3).Value = "未检测到mac地址"rn End Ifrn End SubrnEnd Classrnrn[/code]

没有更多推荐了,返回首页