#!/bin/env python#-*- coding:utf-8 -*-import osimport sysfrom subprocess IMPORT POPENDEF GET_FORIEGN_IP (): l = Os.popen ("netstat -ant|grep established|awk ' {print $5} ' |awk -f: ' {print $1 } ' |sort -r|uniq -c |awk ' {print $2} ' |grep -v ' and ' |grep -v ' Address ' |grep -v ' 0.0.0.0 ' > foreign_ip.txt ") def list_different (): list1=[] f = open (' Foreign_ip.txt ', ' R ') for line in f.readlines () : line1= Line.replace ("\ n", "") list1.append (line1) &Nbsp; print (List1) list2=[] f = open (' Localgroup.txt ', ' R ') for line in f.readlines (): line1=line.replace ("\ n", "") list2.append (line1) print (LIST2) l = [x for x in list1 if x not in list2] print (L) def get_time (): d = os.popen (' echo ' $ (date +%y%m%d_%h:%m:%s) ">>/root/1.txt ') if __name__ == ' _ _main__ ': &nbsP; get_foriegn_ip () list_different () get_time ()
The IP that is associated with this server program is written to the file first Localgroup.txt
Python script gets the server external connection IP and removes the IP that is associated with the non-local server program