Nmap Service Resolution

Nmap
Service Resolution
Port Mapping
nmap-services
nmap-service-probes
Line Handling
Comment Removal
This article discusses how Nmap, a popular network scanner, improves service resolution by using `nmap-services` and `nmap-service-probes`. The process involves parsing lines, removing comments, and separating data into three components per line. This allows for more accurate port mappings and enhances the overall capabilities of Nmap in network discovery.
Published

April 3, 2024


There are two files we are interested in.

The default service to port mapping in Python socket module is incomplete.

# find that with mlocate
# file_path = '/usr/share/nmap/nmap-services'
file_path = "./nmap-services"
with open(file_path, 'r') as f:
line_list = f.read().split('\n')
for line in line_list:
if line.startswith("#"):
# it is a comment
continue
else:
# process this line
content = line.split('#')[0].strip() # strip away comments
components = content.split(" ")
# must be three.
assert len(components) == 3, f"abnormal component count for content: '{content}'"