Created
May 31, 2019 07:05
-
-
Save Santaro255/70f980352cbfe7134c875a19d299089b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pysnmp.hlapi import * | |
import pandas as pd | |
community = "public" | |
def get_model(ip): | |
errorIndication, errorStatus, errorIndex, varBinds = next( | |
getCmd(SnmpEngine(), | |
CommunityData(community, mpModel=0), | |
UdpTransportTarget((ip, 161)), | |
ContextData(), | |
ObjectType(ObjectIdentity('1.3.6.1.2.1.25.3.2.1.3.1'))) | |
) | |
if errorIndication: | |
print(errorIndication) | |
elif errorStatus: | |
print('%s at %s' % (errorStatus.prettyPrint(), | |
errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) | |
else: | |
for oid,value in varBinds: | |
return value | |
def get_name(ip): | |
errorIndication, errorStatus, errorIndex, varBinds = next( | |
getCmd(SnmpEngine(), | |
CommunityData(community, mpModel=0), | |
UdpTransportTarget((ip, 161)), | |
ContextData(), | |
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'))) | |
) | |
if errorIndication: | |
print(errorIndication) | |
elif errorStatus: | |
print('%s at %s' % (errorStatus.prettyPrint(), | |
errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) | |
else: | |
for oid,value in varBinds: | |
return value | |
device_names = [] | |
device_models = [] | |
device_ips = [] | |
net = '172.16.47' | |
for second in range(1,255): | |
print(str(net)+'.'+str(second)) | |
device_models.append(get_model(str(net)+'.'+str(second))) | |
device_ips.append(str(net)+'.'+str(second)) | |
device_names.append(get_name(str(net)+'.'+str(second))) | |
d = {'model': device_models, 'ip': device_ips, 'name': device_names} | |
df = pd.DataFrame(data=d) | |
df.to_csv('.\out_' + str(net) + '.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment