Enable Ident with your Socket Bot
Author: Kintar0
Date: August 28, 2000
Written for Clan X Scripterz

When you use an mIRC to connect to a irc server, it is able to act as an Ident Server. You can choose to enable this feature or not. However, this feature whether turned on or not wont respond to a socket connection; therefore, you would want to be able to enable this in a socket bot as well.

Ever wonder what the 'Enable Ident Server' checkbox in mIRC Options does? Well this is it. It let's mIRC run as an ident server. When a server requests identification, mIRC will send that information and establish your identity. This will get rid of the ~ symbol in your socket bot's ident (nick!~ident@host.domain). Identification is usually not necessary but some servers do not allow access if you are not identified properly. Improperly identifying would result in the server refusing the connection and send an error.

IRC servers usually request ident on port 113 so that would mean we need to be listening to port 113 for any connections. When the server requests ident information, it will send out two numbers in this format:

(Server Port) , (Client Port)

Example: 1234 , 6667

To identify or respond to this properly, you would need to be listening to port 113 for any connections. Using /socklisten you can make mIRC listen to that port. In response, the client (your socket bot) would reply to the server using the information it sent, the two ports. To properly respond, the client should reply with the two ports given in reverse order.

That's not it though. You will need to supply more information. You'll need to specify the Response Type, System, and Identity as well. The response type for your socket bot should be USERID. The System parameter should be UNIX, anything else most likely wont work. Finally, the Identity part is used to specify your ident. This will be the part in front of the @ in your address. (i.e. socketbot@user50.aol.com).

You should note that you should not and can't use special characters for your ident. You may only use numbers 0-9, letters A-Z and a-z, and the symbols _ and - so anything else will cause the server to send an error reply. This would result in having your socket bot disconnected from the server.

Here's how and what your socket bot should reply:

(Client Port) , (Server Port) : USERID : UNIX : (ident)

  Server sends: 1234 , 6667
  Socket Bot replies: 6667 , 1234 : USERID : UNIX : SocketBot

Notice the ports, they are simply reversed. Our 'ident' parameter currently contains 9 characters in length. The maximum allowed is 10 total charaters, anything beyond this will be cut off. If you specify a space, the parameters in front of the first space will be your ident. Also, the spacing of the example is not necessary, you do not need to include spaces between the parameters.

Now that we have established Ident's request and response formats, we can now use a mIRC script to let our socket bot enable Ident. The following section should go into your remotes, you may just use what is shown below or if you are fairly familiar with scripting and sockets then you should just add it to your current socket bot's code.

alias bot {
  socklisten bot 113
  sockopen bot_x irc.dal.net 6667

on *:socklisten:bot: {
  var %_r = $r(1,500)
  sockaccept bot_ [ $+ [ %_r ] ]
  sockclose bot

on *:sockopen:bot_x: {
  sockwrite -n bot_x nick SocketBot
  sockwrite -n bot_x user SocketBot . . . SocketBot

on *:sockread:bot*: {
  sockread %_sb
  tokenize 32 %_sb
  var %_ntoks = $numtok($1-,44)
  if (%_ntoks == 2 && $1,$3 isnum) {
    sockwrite -n $sockname $3 , $1 : USERID : UNIX : SocketBot
  if ($1 == PING && $2) { sockwrite -n $sockname PONG $2- }
  if ($2 == 376) { echo 4 -a SocketBot Successfully Connected... }

Now, let's take a closer look at the code. The coding itself shouldn't be too hard to understand, a simple alias and 3 rather small events. Let's explain what the script does.

First, the alias bot will open 2 socket connections, one listens for connections on local port 113 named bot, and the second connection opens a connection to irc.dal.net on port 6667 named bot_x.

Second, the on socklisten event will trigger when the server attempts to send information on port 113. When the event is triggered, the script will sockaccept the connection and recieve the data which the server tries to send. When the data has been recieved, the script closes port 113 and no longer listens to that port. This keeps your system a bit more secure, if you left port 113 open, anyone would be able to connect to you using that port and that could possiblly result in unwanted security risks.

The on sockopen is used to send information to irc.dal.net. As soon as you open the socket connection with bot_x, which connects to irc.dal.net, the script will send your nickname and user information to the server, registering you for a connection attempt.

Finally, the on sockread event is used to read most socket information which comes through to you on any socket matching bot*. We use the /sockread command to define %_sb as the information which the server sent to us. Next, we have simplified the variable into parameters using /tokenize, which is seperated by spaces(Ascii Character 32). This allow's use to use $1 $2 $3 and so on instead of $gettok(%_sb,1,32)..etc. The line if (%_ntoks == 2 && $1,$3 isnum) { and the two lines below it are what we use for your socket bot's ident routine. What it does is it checks to see if the information sent has 2 parameters, which has a comma as a seperator, and it check is the 2 parameters are numbers. Now, if that matches, that would mean the server is requesting an ident response. The script will send in information we need to identify to the server using the format we discussed above. That is all we need to enable ident on your socket bot. The last 2 lines of code check server PING's and replies to them so you do not timeout. Some server's require you to reply to this ping request before connecting. The last line check's for the "End of /motd" data, which 376 is the raw numeric, and let's you know that your bot has successfully connected to irc.dal.net on port 6667.

That end's the socket bot identification protocol. I hope the script and explanations above help you out with your socket bot. This section is not at all a useful socket bot but just a bot which connects to irc, and properly identifies. A useful socket bot would need a lot more code and especially more error checking. You should have noticed that there isn't much to it but getting the format correct can be a bit confusing if you do not do your reading. This goes for almost anything when you are learning.

A last thought, I would suggest that you also read into the Identification Protocol RFC (RFC1413) for more information and a better understanding.

If you find that this script does not work or has any bug's and/or error's, please let me know by emailing me at kintar0@team-clanx.net

Remember to check back here on our site http://www.team-clanx.net/ for more information , articles, and updates. And thank you for visiting us!