Skip to content

Simple IRC Server

Overview

ircd.sh is a minimalist IRC server implemented as a Bash script, designed for testing IRC clients or demonstrating basic IRC interactions. It responds to standard IRC protocol commands such as PING, NICK, USER, JOIN, and PRIVMSG.

Features

  • Ping-Pong Handling: Responds to PING requests from clients.
  • Nick Management: Handles basic nickname assignments.
  • User Registration: Provides a welcome message upon user connection.
  • Channel Joining: Allows clients to join channels and returns basic channel information.
  • Private Messaging: Enables simple message exchange between users or channels.

Requirements

  • Bash environment (Unix/Linux/macOS)
  • Netcat (nc) or a similar tool to handle TCP connections

Usage

Make the script executable

chmod +x ircd.sh

Start the IRC server listening on a specified port (e.g., 6667)

nc -lkp 6667 -e ./ircd.sh
  • Connect using your favorite IRC client to localhost on the specified port.

Full Script

#!/bin/bash
# Author: wuseman@bugcrowdninja.com
# License: WTFPL <http://www.wtfpl.net/>

while read -r line; do
    echo "Received: $line" >&2

    if [[ $line == PING* ]]; then
        echo "PONG :${line#PING :}"
    fi

    if [[ $line == NICK* ]]; then
        NICK=${line#NICK }
        echo ":$NICK!$NICK@localhost NICK $NICK"
    fi

    if [[ $line == USER* ]]; then
        echo -e ":localhost 001 $NICK :Welcome to the this private irc server, \e[1;32m$NICK\e[0m - Enjoy your stay! You are here because of one reason, trust!"
    fi

    if [[ $line == JOIN* ]]; then
        CHANNEL=${line#JOIN }
        echo ":$NICK!$NICK@localhost JOIN $CHANNEL"
        echo ":localhost 332 $NICK $CHANNEL :Welcome to $CHANNEL"
    fi

    if [[ $line == PRIVMSG* ]]; then
        TARGET=${line#PRIVMSG }
        MESSAGE=${TARGET#* }
        TARGET=${TARGET%% *}
        echo ":$NICK!$NICK@localhost PRIVMSG $TARGET :$MESSAGE"
    fi
done