#!/usr/bin/env python
# NetSplit Parser - Developed by acidvegas in Python (https://acid.vegas/random)
import os
import re
import sqlite3
import time
import urllib.request
# Settings
throttle = 3
# Globals
db_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'netsplit.db')
db = sqlite3.connect(db_file)
sql = db.cursor()
def db_add(name, address, port, ssl):
sql.execute('INSERT INTO SERVERS (NAME,ADDRESS,PORT,SSL) VALUES (\'{0}\', \'{1}\', \'{2}\', \'{3}\')'.format(name, address, port, ssl))
db.commit()
def db_setup():
tables = sql.execute('SELECT name FROM sqlite_master WHERE type=\'table\'').fetchall()
if len(tables):
sql.execute('DROP TABLE SERVERS')
sql.execute('CREATE TABLE SERVERS (NAME TEXT NOT NULL, ADDRESS TEXT NOT NULL, PORT INTEGER NOT NULL, SSL INTEGER NOT NULL);')
db.commit()
def get_source(url):
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
source = urllib.request.urlopen(req, timeout=15)
charset = source.headers.get_content_charset()
if charset:
return source.read().decode(charset)
else:
return source.read().decode()
db_setup()
source = get_source('http://irc.netsplit.de/networks/')
networks = re.findall('.*?
((.*?))', source, re.IGNORECASE|re.MULTILINE)
if checker:
servers = re.findall(r'