Python-脚本整理(长期更新)

Posted lyshark

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python-脚本整理(长期更新)相关的知识,希望对你有一定的参考价值。

判断指定端口是否开放

import socket


port_number = [135,443,80]

for index in port_number:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    result = sock.connect_ex((127.0.0.1, index))
    if result == 0:
        print("Port %d is open" % index)
    else:
        print("Port %d is not open" % index)
    sock.close()

 判断指定端口并且实现轮询报警

#By LyShark
#https://www.cnblogs.com/lyshark

import
requests import sys import json import socket import time def dingding(title,text): dingding_url = https://oapi.dingtalk.com/robot/send?access_token=6d11af3252812ea50410c2ccb861814a69ed11b2306606934a5d4ca9f2c8c09 data = {"msgtype": "markdown","markdown": {"title": title,"text": text}} headers = {Content-Type:application/json;charset=UTF-8} send_data = json.dumps(data).encode(utf-8) requests.post(url=dingding_url,data=send_data,headers=headers) def net_scan(): port_number = [80,135,443] for index in port_number: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex((127.0.0.1, index)) if result == 0: print("Port %d is open" % index) else: return index sock.close() while True: dingding("Warning",net_scan()) time.sleep(60)

 

以上是关于Python-脚本整理(长期更新)的主要内容,如果未能解决你的问题,请参考以下文章

Bash/Shell-脚本整理(长期更新)

Bash/Shell-脚本整理(长期更新)

小程序各种功能代码片段整理---持续更新

常见面试题整理--Python概念篇

小兵出品1-15-2021持续更新Hackintosh黑苹果长期维护机型整理清单

6-19-2020更新Hackintosh黑苹果长期维护机型整理清单