-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathirc-send-oftc.py
executable file
·89 lines (62 loc) · 1.84 KB
/
irc-send-oftc.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
#!/usr/bin/env python2.7
## Written by MDrights, at July 12, 2017.
## Changelog
## 2018.04.07 Updated for aqi-share project (use OFTC)
## 2019.06.30 Send my OONI probe log; can send via Tor.
import socket
import sys
import time
content_file = sys.argv[1]
# Create a Socket
try:
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
print 'Socket Created.'
host = ''
port = 6667 # 6697
#remote_ip = '109.74.200.93'
remote_ip = '188.240.145.40'
# Connect to OFTC.net
try:
irc.connect((remote_ip, port))
except socket.error, msg:
print 'Failed to connect: ' + str(msg[0]) + ', Saying: ' + msg[1]
sys.exit()
print 'Socket connected to ' + remote_ip
# Associating:
channel = "#aqi-data-share"
botnick = "CSObot"
gecos = 'A bot helping Civil Society Organisations in China.'
command = ''
irc.send("NICK " + botnick + "\n")
irc.send("USER " + gecos + "* 8 :" + gecos + "\n")
irc.send("JOIN " + channel + "\n")
#irc.send("PRIVMSG" + channel + " " + command + " " + "\n")
# Send message from files
#data = open('/tmp/run-ooniprobe.log', 'rU')
data = open(content_file, 'rU')
#try:
# message = data.read()
#finally:
# data.close()
# Receive data
while True:
reply = irc.recv(4096)
# print reply
code = reply.split()
# print code
try:
# if code[-7] == '366': # Check the reversed 7th element when connecting to OFTC normally, but should check the reversed 13th element when using Tor.
if code[-13] == '366' or code[-7] == '366':
for message in data:
print 'Sending Messages ...'
irc.send("PRIVMSG" + " " + channel + " :" + message + "\r\n")
time.sleep(1)
print 'Message sent.'
break
except:
pass
irc.close()
print 'Done!'