简单的python端口扫描器

时间:2019-05-04 05:33:03

标签: python-3.x port scapy nmap

有人可以为特定的IP提供基于python 3的端口扫描程序。例如,程序将要求扫描ip并扫描该ip中特定的开放端口范围。

2 个答案:

答案 0 :(得分:0)

使用python中已经存在的nmap库。

答案 1 :(得分:0)

它将扫描网络中连接的IP。需要安装nmap。支持Ubuntu。

from tkinter import * 
from tkinter import scrolledtext
import tkinter.messagebox
import datetime
import subprocess
from subprocess import Popen, PIPE
import re
import pandas as pd

df = ()
def ipget():

    i = 'nmap -sP 192.168.1.*'
    output = subprocess.getoutput(i)
    a = str(output).replace("Nmap","").replace("Starting  7.01 ( https://nmap.org ) at","").replace("scan report for","").replace("Host is up","").replace("latency","").replace("done: 256 IP addresses ","")
    a1 = re.sub(r"(\(.*?\)\.)", "", a)
    a2 = re.sub(r'(?m)^\s*', '', a1)
    ms = re.findall(r'\n([^\s]*)\s+\((\d+\.\d+\.\d+\.\d+)\)', a2)
    df = pd.DataFrame(ms, columns=['User', 'IP_Address'])
    txt.insert("end-1c", df)


def searchname(df):

        i = 'nmap -sP 192.168.1.*'
        output = subprocess.getoutput(i)
        a = str(output).replace("Nmap","").replace("Starting  7.01 ( https://nmap.org ) at","").replace("scan report for","").replace("Host is up","").replace("latency","").replace("done: 256 IP addresses ","")
        a1 = re.sub(r"(\(.*?\)\.)", "", a)
        a2 = re.sub(r'(?m)^\s*', '', a1)
        ms = re.findall(r'\n([^\s]*)\s+\((\d+\.\d+\.\d+\.\d+)\)', a2)
        df = pd.DataFrame(ms, columns=['User', 'IP_Address'])
        inputtxt=txt2.get("1.0","end-1c")
        search_data=  (df[df['User'].str.contains(inputtxt)])
        txt.insert("end-1c", search_data)

timestamp = datetime.datetime.now().strftime("%b %d")
window = Tk()
window.title("LAN Checker")
window.geometry('375x270')
Label(window, 
        text="IPs Connected in LAN",
        fg = "blue",
        bg = "red",
        font = "Verdana 8 bold").pack()
Label(window, 
        text="Day : {}".format(timestamp),
        fg = "red",
        bg = "yellow",
        font = "Verdana 9 bold").pack()
Label(window, 
        text="Enter name of person to search his IP",
        fg = "blue",
        bg = "white",
        font = "Verdana 8 bold").pack()
txt2 = scrolledtext.ScrolledText(window,width=20,height=1)
txt2.pack()
txt = scrolledtext.ScrolledText(window,width=50,height=10)
txt.pack()

btn = Button(window, text="Scan all person IPs", command=lambda: ipget(),fg='white',bg="green")
btn.place(x = 180,y = 235)
btn = Button(window, text="Search Person IP", command=lambda: searchname(df),fg='white',bg="blue")
btn.place(x = 15,y = 235)

window.mainloop()