端口监控脚本

简介: 端口监控脚本
#!/usr/bin/python#-*-coding:utf8-*-import time
import socket
import message_all
import dMonitorConfig
timeout =3socket.setdefaulttimeout(timeout)
send_mail =[]
def write(con):
    txt = open('/home/maxgao/port_send_count','a')
    txt.write("%s\n" %con)
    txt.close()
def tel(i,port,):
    try:
        port = int(port)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((i, port))
if result ==0:
#         pass            print ("monitor %s:%s telnet ok" % (i,port ))
else:
            print 'first telnet error...try again'            print 'sleep 3 sec ...'            time.sleep(3)
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            result = sock.connect_ex((i, port))
if result ==0:
                pass
else:
                print "second telnet %s port %s is error !" %(i,port),starttime
                send_mail.append("%s :%s ClientSocket Error! " %(i,port))
        sock.close()
    except Exception as e:
        pass
def main():
# target =[dMonitorConfig.d_monitor,dMonitorConfig.local_port]# rs = {}# for t in target:#     rs.update(t)# print rssend_count=0hour=time.strftime("%Y-%m-%d %H", time.localtime( time.time() ) )
write(starttime)
for hostname,scanIP in dMonitorConfig.d_monitor.items():
        admin = scanIP[0]
#print type(admin),admin#print "localhost:",hostname+"admin is:",scanIP[0]+"remote ip :",scanIP[1:] for remotelist in scanIP[1:]:
            remoteIP = remotelist.split(":")[0]
            remotePort = remotelist.split(":")[1]
            tel(remoteIP,remotePort)
    print send_mail
    f = open('/home/maxgao/port_send_count','r')
for con in f.readlines():
if hour in con:
            send_count+=1if len(send_mail)>=1 and send_count <=5:
        message_all.mailTo("ops_monitor",["xxx@163.com"],"Port Scan Report","监控点%s --   请求异常IP及端口信息 %s" % (hostname,send_mail))
write(hour)
if __name__ =="__main__":
    starttime = time.ctime(time.time())
    print starttime
    main()
#stoptime = time.ctime(time.time())


目录
相关文章
|
4月前
|
监控 网络协议 Unix
Linux命令-nc(端口监控、文件传输、反弹shell等)
Linux命令-nc(端口监控、文件传输、反弹shell等)
106 0
|
5月前
|
数据采集 Prometheus 监控
监控利器之Prometheus基于Blackbox_exporter监控服务的端口
监控利器之Prometheus基于Blackbox_exporter监控服务的端口
278 0
|
3月前
|
Java Linux
linux一键启动和停止多个端口服务脚本:springboot项目打jar包指定多个端口
linux一键启动和停止多个端口服务脚本:springboot项目打jar包指定多个端口
|
4月前
|
监控 网络协议 Linux
linux(三十五)网络状态和端口监控 netstat
linux(三十五)网络状态和端口监控 netstat
35 1
|
监控 网络协议 Linux
Linux利用nc命令脚本批量检测服务器指定端口是否开放
nc命令脚本批量检测服务器指定端口是否开放
930 0
Linux利用nc命令脚本批量检测服务器指定端口是否开放
|
运维 Oracle 关系型数据库
【大数据开发运维解决方案】kill占用指定端口进程(定时自动重启weblogic脚本)
上面是总结的定时自动重启weblogic脚本以及如果不慎用root启动weblogic后如何恢复oracle用户的运维。 1、通过ps-ef |grep命令找到想要杀死的进程信息,然后配合awk和sed组织好要杀死的进程清单对应的shell语句,并通过sh命令自动执行kill: ps -ef |grep /home/apache-tomcat-7.0.76/|awk 'NR&amp;gt;1 {print $2}' | sed -e &quot;s/^/kill -9 /g&quot; | sh -
【大数据开发运维解决方案】kill占用指定端口进程(定时自动重启weblogic脚本)
|
Python
python脚本基于端口开启服务识别信息收集
python脚本基于端口开启服务识别信息收集
186 0
|
安全 网络协议 网络安全
【工具】nmap的详细利用-主机发现-端口扫描-系统服务识别扫描-脚本利用
本文适合初学者以及想要进阶的小伙伴们,我们将从最简单的出发,一步步实现工具的精通,此外本文配有视频讲解,让您的理解更近一步。
373 0
|
监控 PHP
PHP+Apache如何监控多个端口和配置多站点
PHP+Apache如何监控多个端口和配置多站点
202 0
|
监控 Shell Python
【zabbix教程九】——zabbix3.0 批量添加端口监控
【zabbix教程九】——zabbix3.0 批量添加端口监控
211 0
【zabbix教程九】——zabbix3.0 批量添加端口监控