比如现在需要对172.16.50.0/24网段的ip进行检查,检查哪些ip现在被占用,哪些ip没有被占用,可以通过ping命令来检查,脚本如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

[root@uatdns01 opt]# vim /opt/ping.sh

#!/bin/bash

. /etc/init.d/functions

for var in {1..254};

do

ip=172.16.50.$var

ping -c2 $ip >/dev/null 2>&1

if [ $? = 0 ];then

action "$ip" /bin/true

else

action "$ip" /bin/false

fi

done

[root@uatdns01 opt]# chmod 755 /opt/ping.sh

[root@uatdns01 opt]# sh /opt/ping.sh

172.16.50.1 [ OK ]

172.16.50.2 [FAILED]

172.16.50.3 [FAILED]

172.16.50.4 [FAILED]

172.16.50.5 [FAILED]

.........

.........

172.16.50.99 [ OK ]

172.16.50.100 [ OK ]

172.16.50.101 [ OK ]

172.16.50.102 [ OK ]

172.16.50.103 [ OK ]

172.16.50.104 [ OK ]

172.16.50.105 [ OK ]

172.16.50.106 [ OK ]

172.16.50.107 [ OK ]

172.16.50.108 [ OK ]

172.16.50.109 [ OK ]

172.16.50.110 [ OK ]

172.16.50.111 [FAILED]

172.16.50.112 [ OK ]

***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************

Logo

更多推荐