python为运维人员打造一个监控脚本 - Go语言中文社区

python为运维人员打造一个监控脚本


前言:

一直想写一个监控方面的脚本,然后想到了运维这方面的

后来就写了个脚本。

0x001准备:

psutil模块

0x02正文:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import time
import re
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import socket
import psutil
while True:
  def jianca():
      print('[+]Write a port to a file')
      querys=os.popen('netstat  -an').read()
      wsd=open('netstat.txt','w')
      wsd.write(querys)
      wsd.close()
  jianca()
 
  def swsd():
      global usd,ow
      wsd=open('netstat.txt','r')
      swd=wsd.read()
      odf=re.findall('(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d):(3389)',swd)
      usd=odf[0]
      print('[+]Query the IP address of a remote connection')
      df=usd[0],usd[1],usd[1],usd[3]
      wdst=".".join(df)
      ow=wdst+":"+usd[4]
      print(usd[0],'.',usd[1],'.',usd[2],'.',usd[3]+":",usd[4])
  swsd()
 
  def ipdw():
      global wdf,ip,timsd
      s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
      dw=s.connect(('8.8.8.8',80))
      ip=s.getsockname()[0]
      print('[+]loacl IP:',ip)
      wdf= 版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/shunfa888/article/details/79683447
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 18:26:48
  • 阅读 ( 1629 )
  • 分类:运维

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢