-
Notifications
You must be signed in to change notification settings - Fork 2
/
hexchat.py
93 lines (85 loc) · 3.17 KB
/
hexchat.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
#!/usr/bin/env python
import logging
import sys
import argparse
import time
import shutil
import os
from master import master
from stanza_plugins import register_stanza_plugins
# Python versions before 3.0 do not use UTF-8 encoding
# by default. To ensure that Unicode is handled properly
# throughout SleekXMPP, we will set the default encoding
# ourselves to UTF-8.
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
else:
raw_input = input
if __name__ == '__main__':
register_stanza_plugins()
parser = argparse.ArgumentParser(description='hexchat commands')
parser.add_argument(
'--logfile', dest='logfile', type=str, nargs=1,
help='the log file'
)
parser.add_argument(
'--debug', const="debug", nargs='?', default=False,
help='run in debug mode'
)
parser.add_argument(
'--login', dest='login', type=str, nargs='+',
help="login1 'password1 login2 'pasword2' ...", required=True
)
parser.add_argument(
'--whitelist', dest='whitelist', nargs='*', default=None,
help='whitelist of ips and ports this computer can connect to. ip1 port1 ip2 port2 ...'
)
parser.add_argument(
'--client', dest='client', type=str, nargs='+', default=False,
help='Ports to listen on and JIDs and ports to forward to. <local ip1> <local port1> <server jid> <remote ip1> <remote port1> ...'
)
parser.add_argument(
'--num_logins', const='num_logins', type=int, nargs='?', default=1,
help='number of times to login to each account'
)
parser.add_argument(
'--sequential_bootup', const='sequential_bootup', nargs='?', default=False,
help='Some computers need to login to each account sequentially. If hexchat never boots up, try setting this option.')
parser.add_argument(
'--take_measurements', const='take_measurements', nargs='?', default=False,
help='Measure rates at which sockets are sending data.'
)
args=parser.parse_args()
if args.debug:
logging.basicConfig(filename=args.logfile[0], level=logging.DEBUG)
else:
logging.basicConfig(filename=args.logfile[0], level=logging.WARN)
username_passwords = []
index = 0
while index < len(args.login):
username_passwords.append((args.login[index], args.login[index + 1]))
index += 2
if args.whitelist == None:
whitelist = None
else:
whitelist = []
index = 0
while index < len(args.whitelist):
whitelist.append((args.whitelist[index], int(args.whitelist[index + 1])))
index += 2
master0 = master(
username_passwords, whitelist, args.num_logins,
args.sequential_bootup, args.take_measurements
)
if args.client:
index = 0
while index < len(args.client):
master0.create_server_socket(
(args.client[index], int(args.client[index + 1])),
args.client[index + 2],
(args.client[index + 3], int(args.client[index + 4]))
)
index += 5
while True:
time.sleep(1)