# nmap get exclude top 1000 ports ###### tags: `service search engine` - Extract the list of the top 100 ports: - `nmap -oG - -v --top-ports 100 | awk -F'[);]' '/Ports/{print $2}' > top-100` - Extract list of the top 1000 ports: - `nmap -oG - -v --top-ports 1000 | awk -F'[);]' '/Ports/{print $2}' > top-1000` Scan, using `--exclude-ports` when needed: ```shel= nmap --top-ports 100 <targets> nmap --top-ports 1000 --exclude-ports $(cat top-100) <targets> nmap --top-ports 3647 --exclude-ports $(cat top-1000) <targets> ``` result ```shell nmap -oG - -v --top-ports 5000 | awk -F'[);]' '/Ports/{print $2}' > exclude-ports; nmap -oG - -v -p1-65535 --exclude-ports $(cat exclude-ports) | awk -F'[);]' '/Ports/{print $2}' > result ``` ## flatern ports ```python with open('result', 'r') as file: text = file.read().strip() items = text.split(',') with open('flatern_result', 'w') as f: for i in items: if '-' not in i: f.write(i+'\n') continue start, end = tuple(i.split('-')) for j in range(int(start), int(end)+1): f.write(str(j)+'\n') ``` ## reference - https://security.stackexchange.com/questions/170400/nmap-top-ports-range-selection