首页 > 解决方案 > 无法在 Python 中输入(file.xml)

问题描述

我想通过 cmd 输入文件名。所以我用

file1=input("File Scan1: ")

但是当我输入文件名链接 File1.xml 时,Python 告诉我:

Traceback (most recent call last):
  File "compare.py", line 6, in <module>
    file1=input("File Scan1: ")
  File "<string>", line 1, in <module>
AttributeError: type object 'file' has no attribute 'xml'```

How can i solve this?



标签: pythonpython-3.xinputfilenames

解决方案


这是我的代码。它正在比较 2 次 nmap 扫描并确定实际上未使用的 mac 地址

from xml.dom import minidom


print("Compare 2 Nmap Mac Scans /n")
file1=input("File Scan1: ")
file2=input("File Scan2: ")

xmldoc1=minidom.parse(file1)
hosts=xmldoc1.getElementsByTagName('host')
xmldoc2=minidom.parse(file2)

maclist1=[]
maclist2=[]

for host in hosts:
    adress=host.getElementsByTagName("address")
    
    if len(adress) > 1:  
    
        mac=adress[1].attributes["addr"]
        MAC=mac.value
        maclist1.append(MAC)
                

hosts=xmldoc2.getElementsByTagName('host')


for host in hosts:
    adress=host.getElementsByTagName("address")
    
    if len(adress) > 1:  
    
        mac=adress[1].attributes["addr"]
        MAC=mac.value
        maclist2.append(MAC)
        
for i in maclist1:
    for j in maclist2:
        if(i!=j):
            print(i)


推荐阅读