-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
114 lines (91 loc) · 3.62 KB
/
generate.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import geoipgen
from os import _exit
from gui import time
import connection as connection
def byCountryCode(country_code):
cur = connection.mydb.cursor()
cur.execute("select cidr from cidr where country_code='"+country_code+"' and scaned=0 and scanning=0 ORDER BY RAND() LIMIT 1")
resultado = cur.fetchall()
cur.close()
cidr=resultado[0][0]
ip_list=geoipgen.generate.rangeIP(cidr)
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
for i in range(len(ip_list)):
try:
cur = connection.mydb.cursor()
cur.execute("INSERT INTO ip (cidr,ip) VALUES ('"+cidr+"','"+ip_list[i]+"')")
connection.mydb.commit()
cur.close()
print("\033[34m[\033[01m"+time()+"]\033[0m\033[34m Added ("+ip_list[i]+")\033[0m -\033[36m "+country_code+"\033[0m")
except:
print("\033[31m[ "+ip_list[i]+" DUPLICATE ENTRY ]\033[0m")
_exit(0)
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scaned=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=0 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
def byCIDR(cidr):
cur = connection.mydb.cursor()
cur.execute("select cidr,country_code from cidr where cidr='"+cidr+"'")
resultado = cur.fetchall()
cur.close()
cidr=resultado[0][0]
country_code=resultado[0][1]
ip_list=geoipgen.generate.rangeIP(cidr)
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
for i in range(len(ip_list)):
try:
cur = connection.mydb.cursor()
cur.execute("INSERT INTO ip (cidr,ip) VALUES ('"+cidr+"','"+ip_list[i]+"')")
connection.mydb.commit()
cur.close()
print("\033[35m[\033[01m"+time()+"]\033[0m\033[35m Added ("+ip_list[i]+") - "+country_code+"\033[0m")
except:
print("\033[31m[ "+ip_list[i]+" DUPLICATE ENTRY ]\033[0m")
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scaned=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=0 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
def randomCIDR():
cur = connection.mydb.cursor()
cur.execute("select cidr,country_code from cidr where scaned=0 and scanning=0 ORDER BY RAND() LIMIT 1")
resultado = cur.fetchall()
cur.close()
cidr=resultado[0][0]
country_code=resultado[0][1]
ip_list=geoipgen.generate.rangeIP(cidr)
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
for i in range(len(ip_list)):
try:
cur = connection.mydb.cursor()
cur.execute("INSERT INTO ip (cidr,ip) VALUES ('"+cidr+"','"+ip_list[i]+"')")
connection.mydb.commit()
cur.close()
print("\033[35m[\033[01m"+time()+"]\033[0m\033[35m Added ("+ip_list[i]+") - country: "+country_code+"\033[0m")
except:
print("\033[31m[ "+ip_list[i]+" DUPLICATE ENTRY ]\033[0m")
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scaned=1 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()
cur = connection.mydb.cursor()
cur.execute("UPDATE cidr SET scanning=0 WHERE cidr='"+cidr+"'")
connection.mydb.commit()
cur.close()