-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_service_name.py
More file actions
31 lines (23 loc) · 907 Bytes
/
find_service_name.py
File metadata and controls
31 lines (23 loc) · 907 Bytes
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
# -*- coding: utf-8 -*-
# Python 3.6
# Python_networking | find_service_name
# 12.07.2017 Tomasz Wisniewski
import socket
import argparse
def find_service_name(ports, protocol):
ports_lst = ports.strip().split(" ")
try:
for port in ports_lst:
print("Port: {} service name: {}".format(port, socket.getservbyport(int(port), protocol.lower())))
except:
pass
if __name__ == "__main__":
port_help = """In case of request to check multiple ports please use list of port numbers, separated with space and
wrapped in quotation marks, ex:\n
\"21 25 80\"
"""
parser = argparse.ArgumentParser(description="Find service by name")
parser.add_argument("ports", type=str, help=port_help)
parser.add_argument("protocol", default="tcp", type=str, help="TCP or UDP")
args = parser.parse_args()
find_service_name(args.ports, args.protocol)