Because the company is using VMware virtualization technology, each time the virtual machine to allocate a connection to the external network IP address, in addition to the company scale, the new people also need to assign IP address, it is easy to cause the IP address of the bad and IP address conflict,
So we decided to use a script to troubleshoot the idle usage of IP, reduce the time cost of operations, and less IP collisions:
The script reads as follows:
If you want to use an IP address that can be modified to your own company:
#/usr/bin/env Python
#-*-conding:utf-8-*-
Import subprocess
Import threading
Import time
Import re
Ip_num = 256
List_ping_result = []
Class Pingthread (threading. Thread):
def __init__ (self, str_ip, Sleep_time, G_list_p_r):
Threading. Thread.__init__ (self)
Self.sleep_time = Sleep_time
SELF.STR_IP = Str_ip
Self.list_p_r = G_list_p_r
def run (self):
Time.sleep (Self.sleep_time)
Ftp_sub = subprocess. Popen ("Ping%s-n 3"% self.str_ip,
Stdin=subprocess. PIPE, Stdout=subprocess. PIPE, Shell=true)
ret = Ftp_sub.stdout.read ()
Str_ret = Ret.decode ("GBK")
ret_s = Re.search ("TTL", Str_ret)
If ret_s:
Self.list_p_r.append (' ping ok ', self.str_ip)
Else
Self.list_p_r.append (' ping error ', SELF.STR_IP)
def cmp_s (TOUPE_STR):
Str_val = toupe_str[1]
Ret_group = Re.match ("\d*", Str_val[::-1])
Str_ret = Ret_group.group ()
return int (str_ret[::-1])
thread_id = []
For I in Range (Ip_num):
Thread_id.append (0)
Thread_id[i] = Pingthread ("198.9.6.%d"% i, int (I/20), List_ping_result)
Thread_id[i].start ()
Print (I, end= ")
While True:
If Len (list_ping_result) >= Ip_num:
List_ping_result.sort (key=cmp_s)
For I in List_ping_result:
Print (i)
Break
The results are as follows:
Can be verified by a flat command:
Tested using 28 and 29IP:
Python script implementation of corporate office network IP paragraph usage