-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mybruster_SNMP 函数版.py
50 lines (40 loc) · 1.23 KB
/
Mybruster_SNMP 函数版.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/local/bin/ python
# -*- coding: utf-8 -*-
__author__ = 'yangxiaodi'
# https://www.cnblogs.com/yangxiaodi/p/5660431.html
from pysnmp.entity.rfc3413.oneliner import cmdgen
def read_file(filepath):
f = open(filepath).readlines()
return f
def snmp_connect(ip, key):
crack = 0
try:
errorIndication, errorStatus, errorIndex, varBinds = \
cmdgen.CommandGenerator().getCmd(
cmdgen.CommunityData('my-agent', key, 0),
cmdgen.UdpTransportTarget((ip, 161)),
(1, 3, 6, 1, 2, 1, 1, 1, 0)
)
if varBinds:
crack = 1
except:
pass
return crack
def snmp_l():
try:
host = read_file('host.txt')
for ip in host:
ip = ip.replace('\n', '')
passd = read_file('pass.txt')
for pwd in passd:
pwd = pwd.replace('\n', '')
flag = snmp_connect(ip, key=pwd)
if flag == 1:
print("%s snmp has weaken password!!-----%s\r\n" % (ip, pwd))
break
else:
print("test %s snmp's scan fail" % (ip))
except Exception as e:
pass
if __name__ == '__main__':
snmp_l()