diff options
author | Arianit Kukaj <arianit@hax.al> | 2025-05-26 17:35:15 +0000 |
---|---|---|
committer | Arianit Kukaj <arianit@hax.al> | 2025-05-26 17:35:15 +0000 |
commit | f0572ea86ceda0f5df29bb7f05c279092ae7e495 (patch) | |
tree | b273627dd2fe7c6872c5f29f5b00e7ab606d4814 /bots.pl | |
download | IRCbot-sshaccount-f0572ea86ceda0f5df29bb7f05c279092ae7e495.tar.gz IRCbot-sshaccount-f0572ea86ceda0f5df29bb7f05c279092ae7e495.zip |
Localizing REPOSHEADorigin/masterorigin/HEADmaster
Diffstat (limited to 'bots.pl')
-rw-r--r-- | bots.pl | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -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); |