-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
32 lines (25 loc) · 1.05 KB
/
Copy pathindex.py
File metadata and controls
32 lines (25 loc) · 1.05 KB
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
import requests, re, pymysql, datetime, sys, time
if __name__ == '__main__':
condicao = True
while(condicao):
try:
res = requests.get("http://meuip.com/")
myIp = re.compile('(\d{1,3}\.){3}\d{1,3}').search(res.text).group()
db = pymysql.connect(host="host", # your host, usually localhost
user="user", # your username
passwd="pwd", # your password
db="database") # name of the data base
cursor = db.cursor()
f = open("log.txt", "a")
f.write("INSERT INTO global_public_ip_access (ip, date, source) VALUES ( '" + myIp + "', now(), 'source' )")
cursor.execute("INSERT INTO global_public_ip_access (ip, date, origem) VALUES ( '" + myIp + "', now(), 'source' )")
db.commit()
db.close()
# if it's a insert or update, be sure to have db.commit() after the cursor.execute()
f = open("log.txt", "a")
f.write("done")
except:
condicao = False
print(sys.exc_info()[1])
print("stopping execution at " + str(datetime.datetime.now()))
time.sleep(3600)