先给出代码
import sysfrom PyQt5 import uic
from PyQt5.QtWidgets import *from scapy.all import *
import argparse
import logging
from scapy.layers.inet import IP, TCP
from scapy.sendrecv import sr1class MyWindow(QWidget):def __init__(self):super().__init__()self.init_ui()def init_ui(self):self.ui=uic.loadUi("./spec_port_scan.ui")self.ip=self.ui.lineEditself.port=self.ui.lineEdit_2self.textBrowser=self.ui.textBrowserstart=self.ui.pushButtonstart.clicked.connect(self.begin)def tcpScan(self,a,b):# S 代表发送SYN报文print("SSSSSSS")def begin(self):self.ipp=self.ip.text()self.portt=self.port.text().split(' ')print(self.ipp,self.portt)for p in self.portt:port = int(p)print(type(port))self.target = self.ippsend = sr1(IP(dst=self.target) / TCP(dport=port, flags="S"), timeout=2, verbose=0)if (send is None):self.textBrowser.append("ERROR")self.textBrowser.repaint()continue# 如果是TCP数据包elif send.haslayer("TCP"):# 是否是 SYN+ACK 应答if send["TCP"].flags == "SA":# 发送ACK+RST数据包完成三次握手# send_1 = sr1(IP(dst=target) / TCP(dport=port, flags="AR"), timeout=2, verbose=0)self.textBrowser.append( "[+] 扫描主机: %-13s 端口: %-5s 开放" % (self.target, port))self.textBrowser.repaint()elif send["TCP"].flags == "RA":self.textBrowser.append("[+] 扫描主机: %-13s 端口: %-5s 关闭" % (self.target, port))self.textBrowser.repaint()#self.textBrowser.repaint()#print(self.a)if __name__=='__main__':app=QApplication(sys.argv)w=MyWindow()w.ui.show()app.exec()
实现做好ui 界面 后与python相连接
导入 相应的扫描程序 下面给出:有点缝合怪的感觉
from scapy.all import *
import argparse
import logging
from scapy.layers.inet import IP, TCP
from scapy.sendrecv import sr1def tcpScan(target,ports):for port in ports:# S 代表发送SYN报文send=sr1(IP(dst=target)/TCP(dport=port,flags="S"),timeout=2,verbose=0)if (send is None):continue# 如果是TCP数据包elif send.haslayer("TCP"):# 是否是 SYN+ACK 应答if send["TCP"].flags == "SA":# 发送ACK+RST数据包完成三次握手send_1 = sr1(IP(dst=target) / TCP(dport=port, flags="AR"), timeout=2, verbose=0)print("[+] 扫描主机: %-13s 端口: %-5s 开放" %(target,port))elif send["TCP"].flags == "RA":print("[+] 扫描主机: %-13s 端口: %-5s 关闭" %(target,port))if __name__ == "__main__":logging.getLogger("scapy.runtime").setLevel(logging.ERROR)# 使用方式: main.py -H 192.168.1.10 -p 80,8080,443,445parser = argparse.ArgumentParser()parser.add_argument("-H","--host",dest="host",help="输入一个被攻击主机IP地址")parser.add_argument("-p","--port",dest="port",help="输入端口列表 [80,443,135]")args = parser.parse_args()if args.host and args.port:tcpScan(args.host,eval(args.port))else:parser.print_help()