простой сканер портов Python - PullRequest
0 голосов
/ 04 мая 2019

Может ли кто-нибудь дать сканер портов на основе Python 3 для определенного IP-адреса. Например, программа попросит проверить ip и просканировать определенный диапазон открытых портов в этом ip.

Ответы [ 2 ]

0 голосов
/ 27 мая 2019

Будет сканироваться ips, подключенный к сети.Нужно установить 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()
0 голосов
/ 27 мая 2019

Используйте библиотеку nmap, которая уже есть в python.

...