为 python tkinter 解析 nmap xml 输出

问题描述 投票:0回答:1

我是一名学生,我有点迷茫,我有一个学校项目。该项目使用 Linux 命令行,

我正在使用

nmap
python

这是我项目的第一部分:

想法是创建一个 Tkinter 界面,向我们显示恢复 IP 地址、开放端口和主机名的网络扫描结果

这是理想的应用: prototypeApp

这是我在 python 中的代码:


 import os
os.system("clear") #To clear the terminal

print("Welcome : ")
print("[this is most worse in sudo, so if not work, run in sudo]\n") # for problem 
print ("Enter the target you want attack, or Nmap plage ip : ") 
input1 = input() # for scan terminal
nmap_Command = ("nmap -sV --exclude 192.168.1.24 -oX /Users/nils/Desktop/output.xml " +  input1) #temp var for run the command
#print('\nStarting command for this target -> ' + input1) #print a message
os.system(nmap_Command)# run the command
print("\n")

我对解析 xml 输出以及如何获取变量以将它们与 tkinter 一起使用几乎一无所知。我对自己说我要寻找如何在没有 tkinter 的情况下解析文件(在终端上显示)我找到了 freecodecamp 的教程,但是太复杂了,即使是 github 我也不明白如何要使用它,我尝试了很多小时,现在我在这里寻求帮助

我只是在看你是否有方法在终端上显示,我会在 tkinter 之后 dermederai

我试过这个:https://www.freecodecamp.org/news/enhance-nmap-with-python/

但问题是 GitHub 上的代码不一样,我试图用自述文件修复这个问题,但是 import python 坏了。

python xml-parsing nmap
1个回答
0
投票

问题是它是 XML 格式,根本没有用,不能在 tkinter 中使用,但一旦转换为 JSON,可用性也会增加。

代码和输出

例如,这是我的代码:

import subprocess
import xmltodict
import json
from lxml import etree


def scanner(ip):
    command = 'nmap {} -Pn -sV -T4 -O -F -oX {}.xml'.format(ip, ip)
    subprocess.run(command, shell=True)
    # Xml Write
    scan_file = open("{}.xml".format(ip))
    scan_xml = scan_file.read()
    scan_file.close()
    xslt_doc = etree.parse("nmap.xsl")
    xslt_transformer = etree.XSLT(xslt_doc)
    source_doc = etree.parse("{}.xml".format(ip))
    output_doc = xslt_transformer(source_doc)
    output_doc.write("{}.html".format(ip), pretty_print=True)
    json_data = json.dumps(xmltodict.parse(scan_xml), indent=4, sort_keys=True)
    return json_data


def main():
    scanner('127.0.0.1')


if __name__ == "__main__":
    main()

现在,输出将是:

{
    "nmaprun": {
        "@args": "nmap -Pn -sV -T4 -O -F -oX 127.0.0.1.xml 127.0.0.1",
        "@scanner": "nmap",
        "@start": "1681106666",
        "@startstr": "Mon Apr 10 11:34:26 2023",
        "@version": "7.93",
        "@xmloutputversion": "1.05",
        "debugging": {
            "@level": "0"
        },
        "host": {
            "@endtime": "1681106683",
            "@starttime": "1681106666",
            "address": {
                "@addr": "127.0.0.1",
                "@addrtype": "ipv4"
            },
            "distance": {
                "@value": "0"
            },
            "hostnames": {
                "hostname": {
                    "@name": "kubernetes.docker.internal",
                    "@type": "PTR"
                }
            },
            "ipidsequence": {
                "@class": "Busy server or unknown class",
                "@values": "360F,3621,362B,3635,363F,3649"
            },
            "os": {
                "osfingerprint": {
                    "@fingerprint": "OS:SCAN(V=7.93%E=4%D=4/10%OT=135%CT=7%CU=39153%PV=N%DS=0%DC=L%G=Y%TM=6433A6\nOS:FB%P=i686-pc-windows-windows)SEQ(SP=FC%GCD=2%ISR=103%CI=I%II=I%TS=A)SEQ(\nOS:SP=FD%GCD=1%ISR=103%TI=I%CI=I%II=I%SS=S%TS=A)SEQ(SP=FC%GCD=1%ISR=103%TI=\nOS:I%II=I%SS=S%TS=A)OPS(O1=MFFD7NW8ST11%O2=MFFD7NW8ST11%O3=MFFD7NW8NNT11%O4\nOS:=MFFD7NW8ST11%O5=MFFD7NW8ST11%O6=MFFD7ST11)WIN(W1=FFFF%W2=FFFF%W3=FFFF%W\nOS:4=FFFF%W5=FFFF%W6=FFDC)ECN(R=Y%DF=Y%T=80%W=FFFF%O=MFFD7NW8NNS%CC=N%Q=)T1\nOS:(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O\nOS:=%RD=0%Q=)T3(R=Y%DF=Y%T=80%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%\nOS:W=0%S=A%A=O%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=\nOS:)T6(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=\nOS:S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=Z%RU\nOS:CK=G%RUD=G)IE(R=Y%DFI=N%T=80%CD=Z)\n"
                },
                "osmatch": [
                    {
                        "@accuracy": "99",
                        "@line": "69748",
                        "@name": "Microsoft Windows 10 1607",
                        "osclass": {
                            "@accuracy": "99",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10:1607"
                        }
                    },
                    {
                        "@accuracy": "96",
                        "@line": "69513",
                        "@name": "Microsoft Windows 10 1511",
                        "osclass": {
                            "@accuracy": "96",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10:1511"
                        }
                    },
                    {
                        "@accuracy": "96",
                        "@line": "69894",
                        "@name": "Microsoft Windows 10 1703",
                        "osclass": {
                            "@accuracy": "96",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10:1703"
                        }
                    },
                    {
                        "@accuracy": "94",
                        "@line": "76911",
                        "@name": "Microsoft Windows 7 or 8.1 R1",
                        "osclass": [
                            {
                                "@accuracy": "94",
                                "@osfamily": "Windows",
                                "@osgen": "7",
                                "@type": "general purpose",
                                "@vendor": "Microsoft",
                                "cpe": "cpe:/o:microsoft:windows_7"
                            },
                            {
                                "@accuracy": "94",
                                "@osfamily": "Windows",
                                "@osgen": "8.1",
                                "@type": "general purpose",
                                "@vendor": "Microsoft",
                                "cpe": "cpe:/o:microsoft:windows_8.1:r1"
                            }
                        ]
                    },
                    {
                        "@accuracy": "93",
                        "@line": "69416",
                        "@name": "Microsoft Windows 10 10586 - 14393",
                        "osclass": {
                            "@accuracy": "93",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10"
                        }
                    },
                    {
                        "@accuracy": "93",
                        "@line": "69322",
                        "@name": "Microsoft Windows 10",
                        "osclass": {
                            "@accuracy": "93",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10"
                        }
                    },
                    {
                        "@accuracy": "92",
                        "@line": "69953",
                        "@name": "Microsoft Windows 10 1809 - 1909",
                        "osclass": {
                            "@accuracy": "92",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10"
                        }
                    },
                    {
                        "@accuracy": "92",
                        "@line": "69912",
                        "@name": "Microsoft Windows 10 1709 - 1803",
                        "osclass": {
                            "@accuracy": "92",
                            "@osfamily": "Windows",
                            "@osgen": "10",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_10"
                        }
                    },
                    {
                        "@accuracy": "91",
                        "@line": "77637",
                        "@name": "Microsoft Windows 7 SP1",
                        "osclass": {
                            "@accuracy": "91",
                            "@osfamily": "Windows",
                            "@osgen": "7",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_7::sp1"
                        }
                    },
                    {
                        "@accuracy": "91",
                        "@line": "76016",
                        "@name": "Microsoft Windows Server 2012 R2",
                        "osclass": {
                            "@accuracy": "91",
                            "@osfamily": "Windows",
                            "@osgen": "2012",
                            "@type": "general purpose",
                            "@vendor": "Microsoft",
                            "cpe": "cpe:/o:microsoft:windows_server_2012:r2"
                        }
                    }
                ],
                "portused": [
                    {
                        "@portid": "135",
                        "@proto": "tcp",
                        "@state": "open"
                    },
                    {
                        "@portid": "7",
                        "@proto": "tcp",
                        "@state": "closed"
                    },
                    {
                        "@portid": "39153",
                        "@proto": "udp",
                        "@state": "closed"
                    }
                ]
            },
            "ports": {
                "extraports": {
                    "@count": "98",
                    "@state": "closed",
                    "extrareasons": {
                        "@count": "98",
                        "@ports": "7,9,13,21-23,25-26,37,53,79-81,88,106,110-111,113,119,139,143-144,179,199,389,427,443-444,465,513-515,543-544,548,554,587,631,646,873,990,993,995,1025-1029,1110,1433,1720,1723,1755,1900,2000-2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000-6001,6646,7070,8000,8008-8009,8080-8081,8443,8888,9100,9999-10000,32768,49152-49157",
                        "@proto": "tcp",
                        "@reason": "reset"
                    }
                },
                "port": [
                    {
                        "@portid": "135",
                        "@protocol": "tcp",
                        "service": {
                            "@conf": "10",
                            "@method": "probed",
                            "@name": "msrpc",
                            "@ostype": "Windows",
                            "@product": "Microsoft Windows RPC",
                            "cpe": "cpe:/o:microsoft:windows"
                        },
                        "state": {
                            "@reason": "syn-ack",
                            "@reason_ttl": "128",
                            "@state": "open"
                        }
                    },
                    {
                        "@portid": "445",
                        "@protocol": "tcp",
                        "service": {
                            "@conf": "3",
                            "@method": "table",
                            "@name": "microsoft-ds"
                        },
                        "state": {
                            "@reason": "syn-ack",
                            "@reason_ttl": "128",
                            "@state": "open"
                        }
                    }
                ]
            },
            "status": {
                "@reason": "user-set",
                "@reason_ttl": "0",
                "@state": "up"
            },
            "tcpsequence": {
                "@difficulty": "Good luck!",
                "@index": "253",
                "@values": "BBF5E7E9,9B608916,99A6885E,664CF5B5,31BA0288,AB31DF3"
            },
            "tcptssequence": {
                "@class": "1000HZ",
                "@values": "552BF6A,552BFD9,552C046,552C0B3,552C120,552C18E"
            },
            "times": {
                "@rttvar": "404",
                "@srtt": "253",
                "@to": "100000"
            },
            "uptime": {
                "@lastboot": "Sun Apr  9 10:46:13 2023",
                "@seconds": "89310"
            }
        },
        "runstats": {
            "finished": {
                "@elapsed": "17.02",
                "@exit": "success",
                "@summary": "Nmap done at Mon Apr 10 11:34:43 2023; 1 IP address (1 host up) scanned in 17.02 seconds",
                "@time": "1681106683",
                "@timestr": "Mon Apr 10 11:34:43 2023"
            },
            "hosts": {
                "@down": "0",
                "@total": "1",
                "@up": "1"
            }
        },
        "scaninfo": {
            "@numservices": "100",
            "@protocol": "tcp",
            "@services": "7,9,13,21-23,25-26,37,53,79-81,88,106,110-111,113,119,135,139,143-144,179,199,389,427,443-445,465,513-515,543-544,548,554,587,631,646,873,990,993,995,1025-1029,1110,1433,1720,1723,1755,1900,2000-2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000-6001,6646,7070,8000,8008-8009,8080-8081,8443,8888,9100,9999-10000,32768,49152-49157",
            "@type": "syn"
        },
        "verbose": {
            "@level": "0"
        }
    }
}

这是我得到的输出。根据这些数据,您将如何分析这些数据并获得正确的输出。这还涉及将数据转换为字典。

HTML 输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <head>
    <!--generated with nmap.xsl - version 0.9c by Benjamin Erb - http://www.benjamin-erb.de/nmap_xsl.php -->
    <style type="text/css">
/* stylesheet print */
@media print
{
  #menu {
    display:none;
  }

  body {
    font-family: Verdana, Helvetica, sans-serif;
  }
  
  h1 {
    font-size: 13pt;
    font-weight:bold;
    margin:4pt 0pt 0pt 0pt;
    padding:0;
  }

  h2 {
    font-size: 12pt;
    font-weight:bold;
    margin:3pt 0pt 0pt 0pt;
    padding:0;
  }

  h3, a:link, a:visited {
    font-size: 9pt;
    font-weight:bold;
    margin:1pt 0pt 0pt 20pt;
    padding:0;
    text-decoration: none;
    color: #000000;
  }

  p,ul {
    font-size: 9pt;
    margin:1pt 0pt 8pt 40pt;
    padding:0;
    text-align:left;
  }

  li {
    font-size: 9pt;
    margin:0;
    padding:0;
    text-align:left;
  }

  table {
    margin:1pt 0pt 8pt 40pt;
    border:0px;
    width:90%
  }

  td {
    border:0px;
    border-top:1px solid black;
    font-size: 9pt;
  }

  .head td {
    border:0px;
    font-weight:bold;
    font-size: 9pt;
  }
  .noprint { display: none; }
}

/* stylesheet screen */
@media screen
{
  body {
    font-family: Verdana, Helvetica, sans-serif;
    margin: 0px;
    background-color: #FFFFFF;
    color: #000000;
    text-align: center;
  }

  #container {
    text-align:left;
    margin: 10px auto;
    width: 90%;
  }

  h1 {
    font-family: Verdana, Helvetica, sans-serif;
    font-weight:bold;
    font-size: 14pt;
    color: #FFFFFF;
    background-color:#2A0D45;
    margin:10px 0px 0px 0px;
    padding:5px 4px 5px 4px;
    width: 100%;
    border:1px solid black;
    text-align: left;
  }

  h2 {
    font-family: Verdana, Helvetica, sans-serif;
    font-weight:bold;
    font-size: 11pt;
    color: #000000;
    margin:30px 0px 0px 0px;
    padding:4px;
    width: 100%;
    background-color:#F0F8FF;
    text-align: left;
  }

  h2.green {
    color: #000000;
    background-color:#CCFFCC;
    border-color:#006400;
  }

  h2.red {
    color: #000000;
    background-color:#FFCCCC;
    border-color:#8B0000;
  }
   
  h3 {
    font-family: Verdana, Helvetica, sans-serif;
    font-weight:bold;
    font-size: 10pt;
    color:#000000;
    background-color: #FFFFFF;
    width: 75%;
    text-align: left;
  }

  p {
    font-family: Verdana, Helvetica, sans-serif;
    font-size: 8pt;
    color:#000000;
    background-color: #FFFFFF;
    width: 75%;
    text-align: left;
  }

  p i {
    font-family: Verdana, Helvetica, sans-serif;
    font-size: 8pt;
    color:#000000;
    background-color: #CCCCCC;
  }

  ul {
    font-family: Verdana, Helvetica, sans-serif;
    font-size: 8pt;
    color:#000000;
    background-color: #FFFFFF;
    width: 75%;
    text-align: left;
  }

  a {
    font-family: Verdana, Helvetica, sans-serif;
    text-decoration: none;
    font-size: 8pt;
    color:#000000;
    font-weight:bold;
    background-color: #FFFFFF;
    color: #000000;
  }

  li a {
    font-family: Verdana, Helvetica, sans-serif;
    text-decoration: none;
    font-size: 10pt;
    color:#000000;
    font-weight:bold;
    background-color: #FFFFFF;
    color: #000000;
  }

  a:hover {
    text-decoration: underline;
  }

  a.up {
      color:#006400;
  }

  table {
    width: 80%;
    border:0px;
    color: #000000;
    background-color: #000000;
    margin:10px;
  }

  tr {
    vertical-align:top;
    font-family: Verdana, Helvetica, sans-serif;
    font-size: 8pt;
    color:#000000;
    background-color: #FFFFFF;
  }

  tr.head {
    background-color: #E1E1E1;
    color: #000000;
    font-weight:bold;
  }

  tr.open {
    background-color: #CCFFCC;
    color: #000000;
  }
    
  tr.script {
    background-color: #EFFFF7;
    color: #000000;
  }

  tr.filtered {
    background-color: #F2F2F2;
    color: #000000;
  }

  tr.closed {
    background-color: #F2F2F2;
    color: #000000;
  }
    
  td {
    padding:2px;
  }
        
  #menu li {
    display         : inline;
    margin          : 0;
    /*margin-right    : 10px;*/
    padding         : 0;
    list-style-type : none;
  }    
 
  #menubox {
    position: fixed;
    bottom: 0px;
    right: 0px;
    width: 120px;
  }
  
  
  
  /* This section handle's IE's refusal to honor the fixed CSS attribute */
  
  * html div#menubox {
    position: absolute;
    top:expression(eval(
      document.compatMode &amp;&amp; document.compatMode=='CSS1Compat') ?
      documentElement.scrollTop+(documentElement.clientHeight-this.clientHeight) 
      : document.body.scrollTop +(document.body.clientHeight-this.clientHeight));
  }
  /* This fixes the jerky effect when scrolling in IE*/
  * html,* html body {
    background: #fff url(nosuchfile) fixed;
  }

  
 
  .up {
    color: #000000;
    background-color:#CCFFCC;
  }
  
  .down {
    color:#626262;
    background-color: #F2F2F2;
  }

  .print_only { display: none; }
  .hidden { display: none; }
  .unhidden { display: block; }
  
}
</style>
    <title>Nmap Scan Report - Scanned at Mon Apr 10 11:34:26 2023</title>
    <script type="text/javascript">
     
      
                
      function toggle(divID) {
        var item = document.getElementById(divID);
        if (item) {
          item.className=(item.className=='hidden')?'unhidden':'hidden';
        }
      }
           
      function togglePorts(tableID,portState) {
        var table = document.getElementById(tableID);    
        var tbody = table.getElementsByTagName("tbody")[0];
        var rows = tbody.getElementsByTagName("tr");
        for (var i=0; i &lt; rows.length; i++) {
          var value = rows[i].getElementsByTagName("td")[2].firstChild.nodeValue;
          if (value == portState) {
            rows[i].style.display = (rows[i].style.display == 'none')?'':'none';
          }
        }
      }
      
      function toggleAll(portState) {
        var allTables = document.getElementsByTagName("table");
        for (var c=0; c &lt; allTables.length; c++) {
          if (allTables[c].id != "") {
            togglePorts(allTables[c].id, portState)
          }
        }
      }
      
      function init (){
        toggleAll('closed');
        toggleAll('filtered');     
      }     
            
      window.onload = init; 
      
      
    
    </script>
  </head>
  <body>
    <a name="top"/>
    <div id="container">
      <h1>Nmap Scan Report - Scanned at Mon Apr 10 11:34:26 2023</h1>
      <ul id="menu">
        <li>
          <a href="#scansummary">Scan Summary</a>
        </li>
        <li> | <a href="#host_127_0_0_1" class="up">kubernetes.docker.internal (127.0.0.1)
                  </a></li>
      </ul>
      <a name="scansummary"/>
      <hr class="print_only"/>
      <h2>Scan Summary</h2>
      <p>
      Nmap 7.93 was initiated at Mon Apr 10 11:34:26 2023 with these arguments:<br/><i>nmap -Pn -sV -T4 -O -F -oX 127.0.0.1.xml 127.0.0.1</i><br/></p>
      <p>
    Verbosity: 0; Debug level 0</p>
      <p>Nmap done at Mon Apr 10 11:34:43 2023; 1 IP address (1 host up) scanned in 17.02 seconds</p>
      <hr class="print_only"/>
      <a name="host_127_0_0_1"/>
      <h2 class="up">127.0.0.1 / kubernetes.docker.internal<span class="print_only">(online)</span></h2>
      <div id="hostblock_127.0.0.1" class="unhidden"><h3>Address</h3><ul><li>127.0.0.1
            (ipv4)
          </li></ul>

<h3>Hostnames</h3><ul>
<li>kubernetes.docker.internal (PTR)</li>
</ul>
<h3>Ports</h3><p>The 98 ports scanned but not shown below are in state: <b>closed</b></p><ul><li><p>98 ports replied with: <b>reset</b></p></li></ul><table id="porttable_127.0.0.1" cellspacing="1"><tr class="head"><td colspan="2">Port</td><td>State 
          <a href="javascript:togglePorts('porttable_127.0.0.1','closed');"><span class="noprint"><small> (toggle closed [0] </small></span></a><a href="javascript:togglePorts('porttable_127.0.0.1','filtered');"><span class="noprint"><small> | filtered [0])</small></span></a></td><td>Service</td><td>Reason</td><td>Product</td><td>Version</td><td>Extra info</td></tr>


<tr class="open"><td>135</td><td>tcp</td><td>open</td><td>msrpc&#160;</td><td>syn-ack</td><td>Microsoft Windows RPC&#160;</td><td>&#160;</td><td>&#160;</td></tr>
<tr class="open"><td>445</td><td>tcp</td><td>open</td><td>microsoft-ds&#160;</td><td>syn-ack</td><td>&#160;</td><td>&#160;</td><td>&#160;</td></tr>
</table>
<h3>Remote Operating System Detection</h3><ul><li>Used port: <b>135/tcp</b> (<b>open</b>)  </li><li>Used port: <b>7/tcp</b> (<b>closed</b>)  </li><li>Used port: <b>39153/udp</b> (<b>closed</b>)  </li><li>OS match: <b>Microsoft Windows 10 1607</b> (<b>99%</b>)</li><li>OS match: <b>Microsoft Windows 10 1511</b> (<b>96%</b>)</li><li>OS match: <b>Microsoft Windows 10 1703</b> (<b>96%</b>)</li><li>OS match: <b>Microsoft Windows 7 or 8.1 R1</b> (<b>94%</b>)</li><li>OS match: <b>Microsoft Windows 10 10586 - 14393</b> (<b>93%</b>)</li><li>OS match: <b>Microsoft Windows 10</b> (<b>93%</b>)</li><li>OS match: <b>Microsoft Windows 10 1809 - 1909</b> (<b>92%</b>)</li><li>OS match: <b>Microsoft Windows 10 1709 - 1803</b> (<b>92%</b>)</li><li>OS match: <b>Microsoft Windows 7 SP1</b> (<b>91%</b>)</li><li>OS match: <b>Microsoft Windows Server 2012 R2</b> (<b>91%</b>)</li></ul><ul><li class="noprint">OS identified but the fingerprint was requested at scan time. 
          
        <a href="javascript:toggle('osblock_127.0.0.1');"><span class="noprint"><small> (click to expand)</small></span></a></li></ul><div id="osblock_127.0.0.1" class="hidden"><table class="noprint" cellspacing="1"><tr class="head"><td>Operating System fingerprint</td></tr><tr><td><pre>OS:SCAN(V=7.93%E=4%D=4/10%OT=135%CT=7%CU=39153%PV=N%DS=0%DC=L%G=Y%TM=6433A6
OS:FB%P=i686-pc-windows-windows)SEQ(SP=FC%GCD=2%ISR=103%CI=I%II=I%TS=A)SEQ(
OS:SP=FD%GCD=1%ISR=103%TI=I%CI=I%II=I%SS=S%TS=A)SEQ(SP=FC%GCD=1%ISR=103%TI=
OS:I%II=I%SS=S%TS=A)OPS(O1=MFFD7NW8ST11%O2=MFFD7NW8ST11%O3=MFFD7NW8NNT11%O4
OS:=MFFD7NW8ST11%O5=MFFD7NW8ST11%O6=MFFD7ST11)WIN(W1=FFFF%W2=FFFF%W3=FFFF%W
OS:4=FFFF%W5=FFFF%W6=FFDC)ECN(R=Y%DF=Y%T=80%W=FFFF%O=MFFD7NW8NNS%CC=N%Q=)T1
OS:(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O
OS:=%RD=0%Q=)T3(R=Y%DF=Y%T=80%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%
OS:W=0%S=A%A=O%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=
OS:)T6(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=
OS:S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=Z%RU
OS:CK=G%RUD=G)IE(R=Y%DFI=N%T=80%CD=Z)
</pre></td></tr></table></div>






<br/><a href="javascript:toggle('metrics_127.0.0.1');">
    Misc Metrics <span class="noprint"><small> (click to expand)</small></span></a><div id="metrics_127.0.0.1" class="hidden"><table cellspacing="1"><tr class="head"><td>Metric</td><td>Value</td></tr><tr><td>Ping Results</td><td>user-set</td></tr><tr><td>System Uptime</td><td>89310 seconds  (last reboot: Sun Apr  9 10:46:13 2023)
        </td></tr><tr><td>Network Distance</td><td>0 hops</td></tr><tr><td>TCP Sequence Prediction</td><td>Difficulty=253 (Good luck!)</td></tr><tr><td>IP ID Sequence Generation</td><td>Busy server or unknown class</td></tr></table></div></div>
    </div>
    <div id="menubox" class="noprint">
      <a href="#top">
        <small>Go to top</small>
      </a>
      <br/>
      <a href="javascript:toggleAll('closed');">
        <small>Toggle Closed Ports</small>
      </a>
      <br/>
      <a href="javascript:toggleAll('filtered');">
        <small>Toggle Filtered Ports</small>
      </a>
    </div>
  </body>
</html>

解释代码

  • 代码使用子进程运行 nmap 扫描。
  • 然后一旦扫描完成并保存 XML 输出。
  • 使用xmltodict模块将输出进一步转换为字典
  • 一旦字典被转换,它就会返回给用户。
  • 我们还可以在
    nmap.xsl
    文件中生成相同扫描的 HTML 报告。

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.