Я создал образец сценария, просто настройте его в соответствии с вашими потребностями с помощью файла Output.txt
Я использовал socket
для поиска.
import socket
import pandas as pd
array = ['8.8.8.8','216.58.207.78', '127.0.3.3', '33', 'nana' ,'3fe']
dnsData = {'IP':'HOSTNAME'}
for ip in array:
try:
domain = socket.getfqdn(ip) # Generates a tuple in the form of: ('server.example.com', [], ['127.0.0.1'])
if (ip != domain):
dnsData[ip] = domain
else:
dnsData[ip] = "Unable to resolve data"
except socket.herror:
print("Cannot resolve host ip", e)
# Create a Pandas dataframe from some data.
df = pd.DataFrame.from_dict(dnsData, orient = 'index')
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')
# Close the Pandas Excel writer and output the Excel file.
writer.save()