-
Notifications
You must be signed in to change notification settings - Fork 1
/
portservicename.py
62 lines (54 loc) · 1.72 KB
/
portservicename.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys # Disclaimer: This script is for educational purposes only.
import socket
import pyfiglet
def disp():
print("\n"+"*"*65)
print(pyfiglet.figlet_format(" DcapPort"))
print("*\t\t\t\td-c4ptain\t\t\t\t*")
print("*\t\t Dcaptainkenya@gmail.com\t\t\t*")
print("*\t https://www.D-captainkenya.github.io\t\t*")
print("*"*65)
print("\nCheck Common Port Service Names")
print("\n"+"-"*50)
print("\tPort\t\tService")
print("-"*50)
input_port()
def usage():
print("please specify port numbers correctly!")
print("\nUSAGE:")
print("\tpython portservice.py XW XXXX XZ XYZ")
print("EXAMPLE\n\t Python portservice.py 80 21\n")
sys.exit()
def input_port():
try:
# get port arguments
n = len(sys.argv)
if n < 1:
usage()
elif n > 1:
portlis = [int(port) for port in sys.argv[1:]]
port_name(portlis)
else:
usage()
sys.exit()
except ValueError:
usage()
except KeyboardInterrupt:
print("\nKeyboard interrupted. \nExiting...")
sys.exit()
def port_name(portlis):
for p in portlis:
try:
print(f"\t{p} \t--> \t" f"{socket.getservbyport(p, 'tcp')}")
try:
print(f"\t{p} \t--> \t" f"{socket.getservbyport(p, 'udp')} (UDP)")
except:
pass
except:
try:
print(f"\t{p} \t--> \t" f"{socket.getservbyport(p, 'udp')}")
except:
print(f"\t{p} \t--> \tUNIDENTIFIED")
print("\nRarely, ports have different names depending on the protocol using it.\nI did my best.")
if __name__ == "__main__":
disp()