-
Notifications
You must be signed in to change notification settings - Fork 0
/
bound_listener.py
executable file
·39 lines (34 loc) · 1.01 KB
/
bound_listener.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
#! /usr/bin/env python
import sqlite3
import pyjsonrpc
import sys
def update_domain(url, ip):
conn = sqlite3.connect(r"bound.db")
cur = conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS A ( URL TEXT PRIMARY KEY NOT NULL, IP text NOT NULL )')
try:
cur.execute('INSERT or REPLACE into A values ("'+url+'", "'+ip+'")')
print "Insert/Replace of %s, %s successful." % (url, ip)
sys.stdout.flush()
#data = cur.fetchone()[0]
except Exception, e:
print "Insert/Replace of %s, %s unsuccessful." % (url, ip), e
sys.stdout.flush()
#return "URL was: %s, IP was: %s" % (url, ip)
conn.commit()
return 0
class RequestHandler(pyjsonrpc.HttpRequestHandler):
# Register public JSON-RPC methods
methods = {
"update": update_domain
}
# Threading HTTP-Server
http_server = pyjsonrpc.ThreadingHttpServer(
server_address = ('0.0.0.0', 8080),
RequestHandlerClass = RequestHandler
)
print "Starting HTTP server ..."
print "URL: http://localhost:8080"
sys.stdout.flush()
#http_server.serve_forever()
http_server.serve_forever()