2014-12-07 31 views
-1

好吧,所以我試圖做一個IP掃描儀,只輸出我的網絡上的主機的IP地址,並打開端口。這是我迄今爲止...試圖做一個IP掃描儀,輸出問題

< #!/bin/bash 

nmap 192.168.1.1-254> scan.txt 
cat scan.txt | grep "report" | cut -d " " -f 5 > 

和我的輸出....

FIOS_Quantum_Gateway.fios-router.home 
192.168.1.100 
192.168.1.103 
MT1.fios-router.home 
192.168.1.154 

我試過多次切割和awk組合,但我不能讓它開始工作....有任何想法嗎?

+1

這看起來像你得到你想要的,但你不想DNS解析?使用'-n'標誌來'nmap'。 – 2014-12-07 19:00:24

回答

0

嘗試:

grep -e "report +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"

這將尋找report後跟一個或多個空格,隨後於4。僅分離數字組。有更多的優雅的方式來做到這一點,但不容易看到它在做什麼。

1

比方說您有以下NMAP輸出文件名爲「my_nmap_file.txt」

Starting Nmap 6.40 (http://nmap.org) at 2014-12-07 15:19 EST 
Nmap scan report for 192.168.1.1 
Host is up (0.020s latency). 
Not shown: 991 closed ports 
PORT  STATE SERVICE 
23/tcp open telnet 
53/tcp open domain 
80/tcp open http 
139/tcp open netbios-ssn 
445/tcp open microsoft-ds 
3333/tcp open dec-notes 
5555/tcp open freeciv 
49152/tcp open unknown 
49153/tcp open unknown 
MAC Address: C4:3D:C7:8F:03:19 (Netgear) 

Nmap scan report for 192.168.1.2 
Host is up (0.025s latency). 
All 1000 scanned ports on 192.168.1.2 are closed 
MAC Address: 58:C3:8B:63:52:96 (Samsung Electronics) 

Nmap scan report for 192.168.1.8 
Host is up (0.058s latency). 
All 1000 scanned ports on 192.168.1.8 are closed 
MAC Address: F0:27:65:79:1A:B7 (Murata Manufactuaring Co.) 

Nmap scan report for 192.168.1.6 
Host is up (0.0000070s latency). 
All 1000 scanned ports on 192.168.1.6 are closed 

您可以嘗試在命令行

cat 'my_nmap_file.txt'|grep "Nmap scan report for *" |grep -o -E '[0-9.]+'|sed '1 s#.*#Your Gateway: &#' 

這將匹配找到以下行類似下面並獲取IP地址

Nmap scan report for 192.168.1.2 

輸出

Your Gateway: 192.168.1.1 
192.168.1.2 
192.168.1.8 
192.168.1.6 

注:我添加了一個用於第一線

稱爲'Your Gateway:'小句話我注意到你也想打開端口的IP地址。假如匹配,你可以通過提供NMAP開放的端口給此次被消息。也許我們也可以找到這種模式。