Created
April 14, 2023 11:24
-
-
Save sickcodes/d32bbf065ec56373d98dce54eec00c92 to your computer and use it in GitHub Desktop.
Python3 version of @pry0cc https://gist.githubusercontent.com/pry0cc/dd2e7955d0a0222eb6c09cb283a6d614/raw/3c7bd4c20bb7649a944a36507073d9c9ab4100d8/ports.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gist.githubusercontent.com/pry0cc/dd2e7955d0a0222eb6c09cb283a6d614/raw/3c7bd4c20bb7649a944a36507073d9c9ab4100d8/ports.py | |
#!/usr/bin/env python | |
# Author @pry0cc | |
## $ ports.py nmap.xml | |
## 8.8.8.8:80 | |
## 8.8.8.8:443 | |
## 8.8.8.8:3305 | |
# Install requirements: pip install python3-nmap | |
# Usage is something like ./python nmapParse.py scan.xml | |
from nmap import NmapParser | |
import sys | |
def printsortedlistnewlines(lst): | |
output = "" | |
lst = sorted(set(lst)) | |
for l in lst: | |
output += str(l) + "\n" | |
print(output[:-1]) | |
nmap_report = NmapParser.parse_fromfile(sys.argv[1]) | |
#print("Nmap scan summary: {0}".format(nmap_report.summary)) | |
openports = [] | |
opentcp = [] | |
openudp = [] | |
openhosts = [] | |
# Trying to get | |
# PORT PROTOCOL SERVICE VERSION | |
# 443 tcp ssl/http | |
openportprotoserviceversion = [] | |
servicePort = [] | |
servicePortNoBanner = [] | |
servicePortCount = [] | |
for h in nmap_report.hosts: | |
for s in h.services: | |
if s.state != "open|filtered": | |
openports.append(s.port) | |
openhosts.append(h.ipv4) | |
if s.protocol == "tcp": | |
opentcp.append(s.port) | |
else: | |
openudp.append(s.port) | |
openportprotoserviceversion.append(str(h.ipv4) + ":" + str(s.port)) | |
printsortedlistnewlines(openportprotoserviceversion) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment