我正在試圖製作一個腳本,它可以針對一個ip運行nmap並告訴我主機是否啓動以及操作系統。我希望主機和操作系統的細節成爲唯一的輸出。解析外部命令輸出並保存爲變量
ip=$1
nmap -O $ip |while read -r line; do
if [[ `echo $line|grep "1 host up"`] !=0]
then
echo "1 Host is up"
else
echo "No Host"
fi
done
我在這個非常糟糕的,所以任何幫助,您可以給我將不勝感激:)
編輯:樣品NMap的輸出要求
Starting Nmap 5.21 (http://nmap.org) at 2013-07-16 13:18 EDT
Nmap scan report for hostname.domain.com (192.168.1.5)
Host is up (0.00028s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 78:2B:CB:7E:C7:74 (Unknown)
Device type: general purpose
Running: Microsoft Windows XP
OS details: Microsoft Windows XP SP2 or SP3, or Windows Server 2003
Network Distance: 1 hop
OS detection performed. Please report any incorrect results at http://nmap.org/submit/
Nmap done: 1 IP address (1 host up) scanned in 2.44 seconds
非常感謝!上半場對我有幫助。是否有可能讓我在變量中的主機詳細信息或至少回顯它們? – user163161
@ user163161究竟是哪個細節?你的意思是'操作系統細節:'? – user000001
對不起,我以爲我鍵入操作系統的詳細信息...大腦放屁.. – user163161