-2

Can somebody give python 3 based port scanner for a particular ip. For example program will ask ip to be scanned and scan the particular range of open ports in that ip.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
man7
  • 23
  • 5

2 Answers2

0

Use nmap library which is already in python.

Siyavash vaez afshar
  • 1,303
  • 10
  • 12
0

It will scan the ips connected in the network. It needs nmap to be installed. Supports 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()
Smack Alpha
  • 1,828
  • 1
  • 17
  • 37