-
Notifications
You must be signed in to change notification settings - Fork 2
/
scriptClients.py
80 lines (61 loc) · 2.44 KB
/
scriptClients.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
# import socket
# import threading
# import signal
# # Informations de connexion au serveur IRC
# server_ip = "10.13.4.6"
# # server_ip = "localhost"
# server_port = 9090
# # server_password = "2023"
# server_password = "pp"
# # Liste de pseudos disponibles
# available_nicks = []
# for i in range(0, 5000):
# nick = "client_bot{}".format(i)
# available_nicks.append(nick)
# def connect_irc(nick):
# irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# irc_socket.connect((server_ip, server_port))
# irc_socket.send("PASS {}\r\n".format(server_password).encode())
# irc_socket.send("NICK {}\r\n".format(nick).encode())
# irc_socket.send("USER {} 0 * :Client Bot\r\n".format(nick).encode())
# # irc_socket.send("JOIN #teee\r\n".format(nick).encode())
# while True:
# # signal.signal(signal.SIGPIPE, signal.SIG_IGN)
# message = irc_socket.recv(2048).decode()
# print(message)
# for nick in available_nicks:
# thread = threading.Thread(target=connect_irc, args=(nick,))
# thread.start()
import irc.client
import irc.events
import threading
import time
SERVER = '10.13.4.6' #'192.168.1.108'
PORT = 8080
PASSWORD = 'pp'
CHANNELS = ['#channel1', '#channel2', '#channel11', '#channel22','#channel111', '#channel222','#channel1111', '#channel2222'] # Channels to join
NICKNAME_BASE = 'Bot' # Base nickname; will append numbers to this
USERNAME_BASE = 'Ag' # Base username; will append numbers to this
CLIENT_COUNT = 1000 # Number of clients to connect
def on_welcome(connection, event):
for channel in CHANNELS:
connection.join(channel)
def on_join(connection, event):
channel = event.target
connection.mode(channel, "+o {}".format(connection.get_nickname()))
def connect_client(client_id):
nickname = "{}{}".format(NICKNAME_BASE, client_id)
username = "{}{}".format(USERNAME_BASE, client_id)
reactor = irc.client.Reactor()
try:
connection = reactor.server().connect(SERVER, PORT, nickname, password=PASSWORD, username=username)
except irc.client.ServerConnectionError as exc:
print("Connection failed: ", exc)
return
connection.add_global_handler("welcome", on_welcome)
connection.add_global_handler("join", on_join)
reactor.process_forever()
if __name__ == "__main__":
for i in range(CLIENT_COUNT):
threading.Thread(target=connect_client, args=(i+1,)).start()
time.sleep(1) # Stagger connections slightly