新手端口扫描器项目

问题描述 投票:0回答:0

我是 python/编码的新手,在我的课程中遇到了问题。(网络课程) 这绝对不是我的事,我觉得我的大脑不适合这个!

该项目需要一个脚本来:

  • 接受用户 ip 范围输入,例如。子网前缀 192.168.0 子网掩码 255.255.255.0
  • 为每个地址扫描文件中的所有端口(ports.txt 包含端口号 1 - 10)
  • 跳过前 10 个 IP 地址
  • 跳过偶数地址
  • 端口的输出状态(例如端口 1 在 192.168.xx.xx 上关闭)
  • 输出到日志文件(ip_port_log.txt)
  • 输出到 Windows 事件查看器

我曾尝试浏览寻找答案,但在解决问题时遇到了问题:

  • How to accept ip input properly (Decimal in between octets)
  • 如何跳过前 10 个 IP 地址
  • 如何跳过偶数地址
  • 如何将所有事件输出到 Windows 事件查看器 (我只能让最后一个事件显示出来,例如端口 10 在 192.168.xx.xx 上关闭)
  • 我一定也对脚本进行了更改,现在我的端口扫描语句有一个我无法解决的错误? (结果 = s.connect_ex(ip,端口)

任何帮助将不胜感激!谢谢。

import socket
import win32evtlogutil
import win32evtlog

ip = input("Please enter subnet prefix and mask eg. 192.168.68.0 255.255.255.0:")

def portscan():
    file1 = open('ip_port_log.txt', 'w')
    file = open("ports.txt", "r")
    info = file.readlines()
    for ports in info:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = s.connect_ex(ip, ports)
        if result == 0:
            global data
            data = ("Port" + " " + ports + " " + "is open on" + " " + ip)
            print(data)
            file1.write(str(data) + "\n")
        else:
            data = ("Port" + " " + ports + " " + "is closed on" + " " + ip)
            print(data)
            file1.write(str(data) + "\n")
        s.close()
portscan()

port_scan_EVT = "Port scan event"
port_scan_ID = 7040
port_scan_CATEG = 9876
port_scan_STRS = ["Dummy event string {0:d}".format(item) for item in range(10)]
port_scan_DATA = "Dummy Event Data"
win32evtlogutil.ReportEvent(port_scan_EVT, port_scan_ID, eventCategory=port_scan_CATEG,
eventType=win32evtlog.EVENTLOG_WARNING_TYPE, strings=port_scan_STRS, data=port_scan_DATA)

Script

python ip-address event-viewer port-scanning
© www.soinside.com 2019 - 2024. All rights reserved.