python port scanner

Solutions on MaxInterview for python port scanner by the best coders in the world

showing results for - "python port scanner"
Alina
19 Sep 2017
1import socket, argparse, sys
2
3def Main(ip, port):
4    print('-' * 120)
5    print(f'Scanning target: {args.ip}')
6    print(f'Checking port: {args.port}')
7    print('-' * 120)
8
9    try:
10        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11        s.settimeout(0.5)
12        result = s.connect_ex((args.ip, args.port))
13        if result == 0:
14            print(f'Open Port: {args.port}')
15        else:
16            print(f'Port: {args.port} closed')
17        s.close()
18    except KeyboardInterrupt:
19        print('\nExiting program.')
20        sys.exit()
21    except socket.gaierror:
22        print('Hostname could not be resolved.')
23        sys.exit()
24    except socket.timeout:
25        print('Connection timed out.')
26        sys.exit()
27    except socket.error:
28        print("Couldn't connect to server.")
29        sys.exit()
30
31if __name__ == "__main__":
32    parser = argparse.ArgumentParser(description='Scan a port on given hostname or ip')
33    ap = argparse.ArgumentParser(prog='port_scanner.py', usage='%(prog)s [options] -ip "ip or hostname" -port "port to scan"')
34    ap.add_argument('-ip', required=True, type=str, help='ip or hostname')
35    ap.add_argument('-port', required=True, type=int, help='Port to scan')
36    args = ap.parse_args()
37    ip = args.ip
38    port = args.port
39    Main(ip, port)
Liam
13 May 2018
1import socket 
2import threading
3
4target = "127.0.0.1"   # scan local host
5def port_scanner(port):
6    try:
7        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8        s.connect((target, port))
9        print(f"Port {port} is open")
10    except:
11        pass
12
13
14for port in range(1,5050):
15    thread = threading.Thread(target =port_scanner, args=[port])
16    thread.start()
queries leading to this page
how to make a port scanner in pythonpyton scanner portpython port scanner projesipython port scanner for all portsports scanner py pythonpython tool for portsport scanner pythonport scanner using pythonport scanner project pythonport scanner python 3 script beginnerdcp port scanner pythonhow to port scan with pyhonport scanner in pythonpython ipv6 port scannerpython simp 3be port scannercreate your own python port scannermake your own port scanner with pythonhow to make port scanner using py aunship port scanner pypython port scanner scriptpython port scanip port scanner pythonpython local port scannerpython port scannerhow to make an advanced port scanner using pythonpython port scannertpython scan for open ports website python ip port scannercreating a port scanner with pythonmaking a port scanner in pythonhow to make a port scanner pythonport scanner with pythonport scannerpython script for port scanner for a device in your lan networkpython port scanner tutorialnetwork scanner for open port pythoncreate port scanner pythonpython how to make a port scannerpy port scannerport scanner http pythonpython3 port scannerhow to make a port scanner using pythonport scan using python port scanner python 3 scriptpython script find open portshow to create a port scanner in pythontcp port scanner pythonpython scan network ip for open portspython port scanner examplepython quick port scannerport scanner gui pythonpython open port scannerport scanner with python3how to make port scanner using pypython port scanner linuxpyhton script to scan all portspython port scanspython 3 7 port scannerbuilding a port scanner in pythonpython porttscanpython port scanner