1. 程式人生 > >Python-腳本整理(長期更新)

Python-腳本整理(長期更新)

not true strong conn ext con utf-8 log post

判斷指定端口是否開放

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-腳本整理(長期更新)