社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
前言:
一直想写一个监控方面的脚本,然后想到了运维这方面的
后来就写了个脚本。
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 版权协议,转载请附上原文出处链接和本声明。
你可能感兴趣的文章
精选的优质文章
0 条评论
请先 登录 后评论
官方社群GO教程
推荐文章
猜你喜欢发送私信如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作! |