-
Notifications
You must be signed in to change notification settings - Fork 3
/
torSampling2.py
78 lines (52 loc) · 1.32 KB
/
torSampling2.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
#!/usr/bin/pyton
import simplejson
import MySQLdb
import urllib2
import json
import pprint
import sys
import random
import time
from datetime import datetime, timedelta, date
import db2
db_user='tor'
db_pass='torkskan369'
db_name='tor'
db_host='localhost'
data=''
# Indirizzo json dal quale grabbiamo tutte le info
url = "https://onionoo.torproject.org/details?running=true"
# Connect to database
conn = MySQLdb.connect(host=db_host,
user=db_user,
passwd=db_pass,
db=db_name
)
def downlaodNodes_web():
"Scarichiamo i superdati"
connection = urllib2.urlopen(url)
data_raw=connection.read()
try:
data = json.loads(data_raw)
except Exception as e:
print "\n [!] Exception: \n", e
sys.exit()
return data
def newnodes():
# ora vediamo di gestire i nuovi nodi della rete
for i in data['relays']:
lastRestarted = i['last_restarted']
fp = i['fingerprint']
tor_version = i['platform']
db2.insertSample2(conn,fp,scanDateString,lastRestarted,tor_version)
scanDate = datetime.fromtimestamp(time.time())
scanDateString = datetime.strftime(scanDate, "%Y-%m-%d %H:%M:%S")
print "Start [K]",scanDateString
print "Downloading current active nodes",
data=downlaodNodes_web() #ok
print " [K]"
print "Sampling and saving nodes",
newnodes()
print " [K]"
print ("Everything's fine.")
sys.exit()