Analisa a saída nmap do vbscript para retornar apenas o SO

0

Encontrei um utilitário chamado nmap que consulta um endereço IP e retorna o sistema operacional (provável). Nos meus testes, funcionou perfeitamente. Eu gostaria de incorporá-lo em um vbscript e chamá-lo como uma função e retornar apenas a versão do sistema operacional.

Exemplo de saída:

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)
    
por Scott Beeson 25.04.2013 / 21:06

1 resposta

1

Isto parece funcionar muito bem

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)
    
por 25.04.2013 / 21:06