python IP段指定端口扫描

#!/usr/bin/python
# -*- coding: utf-8 -*-
# 查找哪台电脑开了远程端口
from socket import *

# 3389
host = '192.168.11.'

opened_ports = []

for ip in range(1, 254):
    sock = socket(AF_INET, SOCK_STREAM)
    sock.settimeout(1)
    print('scan:{}'.format(ip))
    result = sock.connect_ex((gethostbyname(host + str(ip)), 3389))
    if result == 0:
        print('*********:{}'.format(ip))
        opened_ports.append(ip)

print("Opened ports:")

for i in opened_ports:
    print(i)

posted @ 2022-10-13 14:44  那时一个人  阅读(67)  评论(0)    收藏  举报