python --- 监控客户端是否存活

一、手动监控客户端是否存活
项目思维
这里写图片描述

服务器端192.168.72.130:

root@kali:~# cd /root/python/snmp/
root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc


root@kali:~/python/snmp# cat celie.txt 
192.168.72.129  xuweibo


root@kali:~/python/snmp# cat m_handle.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

from datetime import datetime#导入时间模块
import pickle#导入pickle模块

f = file('h_dic.pkl','rb')#使用rb读取模式打开pickle文件

host_status = pickle.load(f)#使用pickle的load方式打开文件,变成字典

for h,m in host_status.items():#在字典中循环元素
    if len(m) != 0:#如果时间值不为空,则进入
        old_time = m[-1][0]#取时间值出来
        time_diff = (datetime.now() - old_time).seconds#当前时间减去从pickle文件中读取的值,为时间差值
        if time_diff > 30:#如果时间差大于30秒,则进入
            print 'No data received from %s for %s ,please check!' %(h,time_diff)
        else:
            print h,(datetime.now() - old_time).seconds#打印主机ip,时间差值



root@kali:~/python/snmp# cat h_dic.pkl 
(dp0
S'192.168.72.129'
p1
(lp2
(cdatetime
datetime
p3
(S'\x07\xe1\x08\x16\x149\x1b\x02\xd0F'
p4
tp5
Rp6
S'up'
p7
tp8
a(g3
(S'\x07\xe1\x08\x16\x149#\x03\xeag'
p9
tp10
Rp11
S'up'
p12
tp13
a(g3
(S'\x07\xe1\x08\x16\x149*\x01Fd'
p14
tp15
Rp16
S'up'
p17
tp18
a(g3
(S"\x07\xe1\x08\x16\x14:'\x06\x9di"
p19
tp20
Rp21
S'up'
p22
tp23
a(g3
(S'\x07\xe1\x08\x16\x15\x0c\x16\x00=\x9f'
p24
tp25
Rp26
S'up'
p27
tp28
a(g3
(S'\x07\xe1\x08\x16\x15\x0c\x16\te\x8c'
p29
tp30
Rp31
S'up'
p32
tp33
a(g3
(S'\x07\xe1\x08\x16\x15\r\x04\x08W\x91'
p34
tp35
Rp36
S'up'
p37
tp38
a(g3
(S'\x07\xe1\x08\x16\x16\x16\x05\r~\xcb'
p39
tp40
Rp41
S'up'
p42
tp43
a(g3
(S'\x07\xe1\x08\x16\x16\x16\r\x07D\x1d'
p44
tp45
Rp46
S'up'
p47
tp48
a(g3
(S'\x07\xe1\x08\x16\x16\x16-\t\xcea'
p49
tp50
Rp51
S'up'
p52
tp53
a(g3
(S'\x07\xe1\x08\x16\x16\x167\r\xac\x04'
p54
tp55
Rp56
S'up'
p57
tp58
a(g3
(S'\x07\xe1\x08\x16\x16\x17\x15\x0e\t\xfe'
p59
tp60
Rp61
S'up'
p62
tp63
a(g3
(S'\x07\xe1\x08\x16\x16\x17\x16\x05C\xa6'
p64
tp65
Rp66
S'up'
p67
tp68
a(g3
(S'\x07\xe1\x08\x16\x16\x17\x16\n\xd1*'
p69
tp70
Rp71
S'up'
p72
tp73
a(g3
(S'\x07\xe1\x08\x16\x16\x17\x17\x00\xfa^'
p74
tp75
Rp76
S'up'
p77
tp78
as.root@kali:~/python/snmp# 



as.root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc


root@kali:~/python/snmp# cat snmpclient2.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

import socket

host,port = '192.168.72.130',18000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#调用IPv4协议
s.connect((host,port))#连接主机与端口

s.send("up")#客户端给服务器端发送数据“up”

s.close()



root@kali:~/python/snmp# cat snmpserver.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

import datetime#导入时间戳
import SocketServer
import pickle

pfile = 'h_dic.pkl'#定义pickle文件

#读取目录下的celie.txt文件
host_status = {}#新建字典,使用IP地址作为KEY值。作用是来判断每个客户端IP多久与服务器通信一次的
f = open('celie.txt')#调用策略文档,在里面的ip地址就可以通过,并发送信息
while True:
    line = f.readline().split()
    if len(line) == 0:break
    print line[0]#打印第一个IP地址信息
    host_status[line[0]] = []#给字典第一个设置为空,这样后面只要直接追加值就ok了
f.close()


class myMonitorHandler(SocketServer.BaseRequestHandler):
    '''This is the Monitor server'''
    def handle(self):
        recv_data = self.request.recv(1024)#接收客户端数据
        if self.client_address[0] == '192.168.72.130':#如果IP为本机IP地址,就重新写入pickle文件信息
            f2 = file(pfile,'w')#使用pickle模块可写模式打开文件f2
            pickle.dump(host_status,f2)#使用pickle带参数为字典名与文件名
            f2.close()#关闭文件f2

        if self.client_address[0] in host_status.keys():#如果存在字典中的ip地址信息,就返回对应客户端发送的Ip、时间戳、信息    

            #self.client_address为数组('192.168.72.129', 49109)的值。只要当中的IP地址,因此取self.client_address[0]
            #把host_status字典中的self.client_address[0]值即IP地址值赋值有两个值,因此新建个列表,存取两个值时间戳与接收的信息
            #如:{'192.168.72.129': [(datetime.datetime(2017, 8, 20, 21, 29, 59, 415054), 'up')]}
            #host_status[self.client_address[0]] = [(datetime.datetime.now(),recv_data)]

            #直接把元组append进字典
            host_status[self.client_address[0]].append((datetime.datetime.now(),recv_data))

            print 'From %s : %s %s' %(self.client_address,datetime.datetime.now(),recv_data)#打印客户端地址、操作的时间戳值与接收的数据

            #print host_status

        else:#不存在字典中,则如下提示信息
            print "sorry, ip %s is not in the monitor list" % self.client_address[0]

        #打印出192.168.72.129 [(datetime.datetime(2017, 8, 20, 22, 1, 6, 705498), 'up')]
        for t,m in host_status.items():
            print t,m

if __name__ == "__main__":#当自己运行时调用什么什么;当被其他程序调用时调用什么什么,如果被其他程序调用了,下面代码不执行
    host,port = '',18000
    server = SocketServer.ThreadingTCPServer((host,port),myMonitorHandler)#调用TCP的多线程
    server.serve_forever()

root@kali:~/python/snmp# 


root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc
root@kali:~/python/snmp# cat tab.py
#pyhton startup file
import sys
import readline
import rlcompleter
import atexit
import os
#tab completion
readline.parse_and_bind('tab:complete')
#history file
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file,histfile)

del os, histfile, readline, rlcompleter
root@kali:~/python/snmp# 

客户端192.168.72.129

root@72129clent:~# cd /root/python/snmp/
root@72129clent:~/python/snmp# ls
snmpclenit.py  tab.py
root@72129clent:~/python/snmp# cat snmpclenit.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

import socket

host,port = '192.168.72.130',18000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#调用IPv4协议
s.connect((host,port))#连接主机与端口

s.send("up")#客户端给服务器端发送数据“up”

s.close()



root@72129clent:~/python/snmp# cat tab.py 
#pyhton startup file
import sys
import readline
import rlcompleter
import atexit
import os
#tab completion
readline.parse_and_bind('tab:complete')
#history file
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file,histfile)

del os, histfile, readline, rlcompleter
root@72129clent:~/python/snmp# 

客户端192.168.72.1
这里写图片描述

实际运行情况:
服务器端192.168.72.130,先运行

root@kali:~/python/snmp# clear
root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc
root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129
Traceback (most recent call last):
  File "snmpserver.py", line 53, in <module>
    server = SocketServer.ThreadingTCPServer((host,port),myMonitorHandler)#调用TCP的多线程
  File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
root@kali:~/python/snmp# lsof -i :18000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python  22071 root    3u  IPv4  65818      0t0  TCP *:18000 (LISTEN)
root@kali:~/python/snmp# kill -9 220071
-bash: kill: (220071) - No such process
root@kali:~/python/snmp# kill -9 22071
root@kali:~/python/snmp# lsof -i :18000
root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129

在celie.txt白名单中的客户端192.168.72.129运行情况

root@72129clent:~/python/snmp# ls
snmpclenit.py  tab.py
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# ls
snmpclenit.py  tab.py
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# 

服务端192.18.72.130再次查询

root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129
From ('192.168.72.129', 49462) : 2017-08-23 19:58:17.160825 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up')]
From ('192.168.72.129', 49465) : 2017-08-23 19:59:47.717947 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up')]
From ('192.168.72.129', 49466) : 2017-08-23 19:59:48.248083 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up')]
From ('192.168.72.129', 49467) : 2017-08-23 19:59:48.729527 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up')]
From ('192.168.72.129', 49468) : 2017-08-23 19:59:49.121510 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up')]
From ('192.168.72.129', 49469) : 2017-08-23 19:59:49.583931 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up')]
From ('192.168.72.129', 49470) : 2017-08-23 19:59:50.021518 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 21479), 'up')]
From ('192.168.72.129', 49471) : 2017-08-23 19:59:50.384524 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 21479), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 384505), 'up')]
From ('192.168.72.129', 49472) : 2017-08-23 19:59:50.771609 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 21479), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 384505), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 771592), 'up')]
From ('192.168.72.129', 49473) : 2017-08-23 19:59:51.212824 up
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 21479), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 384505), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 771592), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 51, 212794), 'up')]

在服务器端,运行m_handle.py计算客户端192.168.72.129最后时间与最近时间的间隔

root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 77934 ,please check!
root@kali:~/python/snmp# 

重新设置客户端192.168.72.129与服务器端192.168.72.130最近刷新的时间间隔

root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc
root@kali:~/python/snmp# python snmpclient2.py
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 524 ,please check!
root@kali:~/python/snmp# 
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 657 ,please check!
root@kali:~/python/snmp# 

root@kali:~/python/snmp# python snmpclient2.py 
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 226 ,please check!
root@kali:~/python/snmp# 

不在celie.txt白名单中客户端192.168.72.1,运行情况

Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

C:\Users\xwb>cd ..

C:\Users>cd .

C:\Users>cd ..

C:\>cd Python27

C:\Python27>dir
 驱动器 C 中的卷是 OS
 卷的序列号是 6CA3-FD00

 C:\Python27 的目录

2017/08/20  23:03    <DIR>          .
2017/08/20  23:03    <DIR>          ..
2017/03/02  23:37    <DIR>          DLLs
2017/03/02  23:37    <DIR>          Doc
2017/03/02  23:37    <DIR>          include
2017/03/02  23:37    <DIR>          Lib
2017/03/02  23:37    <DIR>          libs
2016/12/17  20:59            38,591 LICENSE.txt
2016/12/17  20:34           474,595 NEWS.txt
2016/12/17  20:55            28,160 python.exe
2016/12/17  20:55            28,160 pythonw.exe
2016/12/03  21:01            56,938 README.txt
2017/03/02  23:38    <DIR>          Scripts
2017/08/20  22:57               291 snmpclinet.py
2017/03/02  23:37    <DIR>          tcl
2017/08/20  22:57    <DIR>          testpy
2017/03/02  23:37    <DIR>          Tools
               6 个文件        626,735 字节
              11 个目录 330,268,655,616 可用字节

C:\Python27>python snmpclinet.py

C:\Python27>python snmpclinet.py

C:\Python27>

服务器端192.168.72.130运行情况:

root@kali:~/python/snmp# lsof -i :18000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python  22071 root    3u  IPv4  65818      0t0  TCP *:18000 (LISTEN)
root@kali:~/python/snmp# kill -9 220071
-bash: kill: (220071) - No such process
root@kali:~/python/snmp# kill -9 22071
root@kali:~/python/snmp# lsof -i :18000
root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129

sorry, ip 192.168.72.1 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 23, 19, 58, 17, 160806), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 47, 717908), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 248039), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 48, 729491), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 121490), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 49, 583895), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 21479), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 384505), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 50, 771592), 'up'), (datetime.datetime(2017, 8, 23, 19, 59, 51, 212794), 'up'), (datetime.datetime(2017, 8, 23, 20, 10, 37, 970177), 'up')]

二、自动监控客户端是否存活

把上面的服务器端的snmpclient2.py脚本内容,合并到m_handle.py脚本中

snmpclient2.py

root@kali:~/python/snmp# cat snmpclient2.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

import socket

host,port = '192.168.72.130',18000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#调用IPv4协议
s.connect((host,port))#连接主机与端口

s.send("up")#客户端给服务器端发送数据“up”

s.close()
root@kali:~/python/snmp# 

合并到m_handle.py脚本中

root@kali:~/python/snmp# cat m_handle.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--

import socket
from datetime import datetime#导入时间模块
import pickle#导入pickle模块

def trigger_dump():#把手动刷新时间间隔snmpclient2.py脚本的内容,写入一个功能函数中,变成软件自动刷新客户端与服务器时间间隔
    host,port = '192.168.72.130',18000
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((host,port))
    s.send('up')
    s.close()

trigger_dump()#每次执行m_handle.py脚本都会自动刷新时间间隔信息

f = file('h_dic.pkl','rb')#使用rb读取模式打开pickle文件

host_status = pickle.load(f)#使用pickle的load方式打开文件,变成字典

for h,m in host_status.items():#在字典中循环元素
    if len(m) != 0:#如果时间值不为空,则进入
        old_time = m[-1][0]#取时间值出来
        time_diff = (datetime.now() - old_time).seconds#当前时间减去从pickle文件中读取的值,为时间差值
        if time_diff > 30:#如果时间差大于30秒,则进入
            print 'No data received from %s for %s ,please check!' %(h,time_diff)
        else:
            print h,(datetime.now() - old_time).seconds#打印主机ip,时间差值

root@kali:~/python/snmp# 

运行情况:
第一步,先运行服务器端192.168.72.130脚本

root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129

在运行在celie.txt白名单中的客户端192.168.72.129

root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# python snmpclenit.py 
root@72129clent:~/python/snmp# 

再次查看服务器端192.168.72.130

root@kali:~/python/snmp# ls
celie.txt  h_dic.pkl  m_handle.py  snmpclient2.py  snmpserver.py  tab.py  tab.pyc
root@kali:~/python/snmp# python snmpserver.py 
192.168.72.129
From ('192.168.72.129', 49582) : 2017-08-24 07:10:45.397587 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up')]
From ('192.168.72.129', 49583) : 2017-08-24 07:10:50.823307 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up')]
From ('192.168.72.129', 49584) : 2017-08-24 07:10:51.315388 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up')]
From ('192.168.72.129', 49585) : 2017-08-24 07:10:51.765921 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up')]
From ('192.168.72.129', 49586) : 2017-08-24 07:11:33.288661 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up')]
From ('192.168.72.129', 49587) : 2017-08-24 07:11:33.764387 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up')]
From ('192.168.72.129', 49588) : 2017-08-24 07:11:34.098857 up
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]
sorry, ip 192.168.72.130 is not in the monitor list
192.168.72.129 [(datetime.datetime(2017, 8, 24, 7, 10, 45, 397565), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 50, 823288), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 315370), 'up'), (datetime.datetime(2017, 8, 24, 7, 10, 51, 765903), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 288644), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 33, 764370), 'up'), (datetime.datetime(2017, 8, 24, 7, 11, 34, 98839), 'up')]

可以实时查看客户端与服务器端的时间间隔

root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 33376 ,please check!
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 16
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 20
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 29
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 34 ,please check!
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 38 ,please check!
root@kali:~/python/snmp# python m_handle.py 
No data received from 192.168.72.129 for 45 ,please check!
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 4
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 5
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 7
root@kali:~/python/snmp# python m_handle.py 
192.168.72.129 17
root@kali:~/python/snmp# 
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐为波

看着给就好了,学习写作有点累!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值