aboutsummaryrefslogtreecommitdiffstats
path: root/bots.pl
diff options
context:
space:
mode:
authorArianit Kukaj <arianit@hax.al>2025-05-26 17:35:15 +0000
committerArianit Kukaj <arianit@hax.al>2025-05-26 17:35:15 +0000
commitf0572ea86ceda0f5df29bb7f05c279092ae7e495 (patch)
treeb273627dd2fe7c6872c5f29f5b00e7ab606d4814 /bots.pl
downloadIRCbot-sshaccount-f0572ea86ceda0f5df29bb7f05c279092ae7e495.tar.gz
IRCbot-sshaccount-f0572ea86ceda0f5df29bb7f05c279092ae7e495.zip
Diffstat (limited to 'bots.pl')
-rw-r--r--bots.pl81
1 files changed, 81 insertions, 0 deletions
diff --git a/bots.pl b/bots.pl
new file mode 100644
index 0000000..b23322b
--- /dev/null
+++ b/bots.pl
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use IO::Socket;
+use List::Util qw(min);
+
+# Open the file containing a list of nicknames
+open(my $fh, "<", "nicks.txt") or die "Can't open file: $!";
+
+# Define the maximum number of bots to connect
+my $max_bots = 500;
+
+# Keep track of the number of bots that have connected
+my $num_bots = 0;
+
+# Loop through each nickname in the file
+while (my $nick = <$fh>) {
+ chomp($nick);
+
+ # Limit the number of bots to the maximum defined
+ last if $num_bots >= $max_bots;
+
+ # Connect to the IRC server using a new socket for each nickname
+ my $socket = IO::Socket::INET->new(
+ PeerAddr => "irc.example.com",
+ PeerPort => 6667,
+ Proto => "tcp",
+ ) or die "Can't connect to server: $!";
+
+ # Send the nickname to the server
+ print $socket "NICK $nick\r\n";
+
+ # Send the user information to the server
+ print $socket "USER $nick 0 * :$nick\r\n";
+
+ # Increment the number of bots that have connected
+ $num_bots++;
+
+ # Fork a new process to handle the connection for this bot
+ my $pid = fork();
+ if (!defined $pid) {
+ # Error in fork, so close the socket and continue to the next bot
+ close($socket);
+ next;
+ } elsif ($pid == 0) {
+ # Child process: Loop to receive messages from the server and respond to them
+ while (1) {
+ # Read a line from the socket
+ my $line = <$socket>;
+
+ # Check if the line is defined (the socket is still open)
+ if (defined $line) {
+ # Check if the server is asking for the nickname to be registered
+ if ($line =~ /^PING\s*:(.*)/) {
+ my $ping = $1;
+ print $socket "PONG :$ping\r\n";
+ }
+
+ # Check if the server has accepted the nickname
+ if ($line =~ /^.* 001 $nick/) {
+ # Join the #text channel
+ print $socket "JOIN #text\r\n";
+ }
+ } else {
+ # The socket has closed, so break the loop
+ last;
+ }
+ }
+
+ # Close the socket and exit the child process
+ close($socket);
+ exit(0);
+ }
+}
+
+# Wait for all child processes to finish
+while (wait() != -1) {}
+
+# Close the file
+close($fh);