从 vbscript 解析 nmap 输出以仅返回操作系统

从 vbscript 解析 nmap 输出以仅返回操作系统

我找到了一个名为nmap查询 IP 地址并返回(可能的)操作系统。在我的测试中,它运行完美。我想将其嵌入到 vbscript 中并将其作为函数调用,然后仅返回操作系统版本。

示例输出:

Starting Nmap 6.25 ( http://nmap.org ) at 2013-04-25 13:30 Central Daylight Time
Initiating Ping Scan at 13:30
Scanning servername (1.2.3.4) [4 ports]
Completed Ping Scan at 13:30, 0.28s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 13:30
Completed Parallel DNS resolution of 1 host. at 13:30, 0.02s elapsed
Initiating SYN Stealth Scan at 13:30
Scanning servername (1.2.3.4) [1000 ports]
Discovered open port 139/tcp on 1.2.3.4
Discovered open port 3389/tcp on 1.2.3.4
Discovered open port 80/tcp on 1.2.3.4
Discovered open port 445/tcp on 1.2.3.4
Discovered open port 3306/tcp on 1.2.3.4
Discovered open port 135/tcp on 1.2.3.4
Discovered open port 1025/tcp on 1.2.3.4
Discovered open port 1066/tcp on 1.2.3.4
Discovered open port 4445/tcp on 1.2.3.4
Completed SYN Stealth Scan at 13:30, 0.40s elapsed (1000 total ports)
Initiating OS detection (try #1) against servername (1.2.3.4)
Nmap scan report for servername (1.2.3.4)
Host is up (0.014s latency).
Not shown: 991 closed ports
PORT     STATE SERVICE
80/tcp   open  http
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
1025/tcp open  NFS-or-IIS
1066/tcp open  fpo-fns
3306/tcp open  mysql
3389/tcp open  ms-wbt-server
4445/tcp open  upnotifyp
Device type: general purpose
Running: Microsoft Windows 2003
OS CPE: cpe:/o:microsoft:windows_server_2003::sp1 cpe:/o:microsoft:windows_server_2003::sp2
OS details: Microsoft Windows Server 2003 SP1 or SP2
Network Distance: 7 hops
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: Incremental

Read data files from: I:\Scott\Utilities\nmap-6.25
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 2.30 seconds
           Raw packets sent: 1020 (45.570KB) | Rcvd: 1020 (41.434KB)

答案1

这似乎很有效

Public function GetOS(ServerName)
    Set objWShell = CreateObject("WScript.Shell") 
    Set objCmd = objWShell.Exec("nmap -O -v " & ServerName) 
    strPResult = objCmd.StdOut.Readall() 
    set objCmd = nothing: Set objWShell = nothing 
    GetOS = "Unknown" 
    if InStr(strPResult,"OS details:")>0 then 
        strTemp1 = split(strPResult,"OS details: ")
        strTemp2 = split(strTemp1(1),vbCrLf)
        GetOS = strTemp2(0)
    end if
End function

wscript.echo GetOS(testserver)

相关内容