Skip to content

Instantly share code, notes, and snippets.

@vivien
Created May 2, 2014 00:38
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save vivien/3b1c2efb80f3f3dde001 to your computer and use it in GitHub Desktop.
Save vivien/3b1c2efb80f3f3dde001 to your computer and use it in GitHub Desktop.
irccat - Using netcat with an IRC channel
#!/bin/sh
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Licensed under the terms of the GNU GPL v3, or any later version.
NICK=irccat42
SERVER=irc.freenode.net
PORT=6667
CHAN="#irccat"
{
# join channel and say hi
cat << IRC
NICK $NICK
USER irccat 8 x : irccat
JOIN $CHAN
PRIVMSG $CHAN :Greetings!
IRC
# forward messages from STDIN to the chan, indefinitely
while read line ; do
echo "$line" | sed "s/^/PRIVMSG $CHAN :/"
done
# close connection
echo QUIT
} | nc $SERVER $PORT | while read line ; do
case "$line" in
*PRIVMSG\ $CHAN\ :*) echo "$line" | cut -d: -f3- ;;
#*) echo "[IGNORE] $line" >&2 ;;
esac
done
@xorgnak
Copy link

xorgnak commented Feb 8, 2015

Awesome.

@scuba323
Copy link

What about when a server pings, and waits for a pong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment