diff options
author | makefu <root@pigstarter.de> | 2013-09-27 15:38:30 +0200 |
---|---|---|
committer | makefu <root@pigstarter.de> | 2013-09-27 15:38:30 +0200 |
commit | b4b735b6a1e14de84edd40ad2badcc1746235696 (patch) | |
tree | 3c8217c678c826afc39ed97af74023ac672d3ff8 | |
parent | d16f89c3016e8ff0da08a85e8d51b79b552a7c5c (diff) |
add network libs
-rw-r--r-- | lib/network | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/network b/lib/network new file mode 100644 index 00000000..9d7ea197 --- /dev/null +++ b/lib/network @@ -0,0 +1,49 @@ +#!/bin/sh +#include core + +anytelnet(){ + # find Telnet or similar and executes it at the end + # requires exist + # if env TELNET is set, will be trying to run this + # Tries the following things: + # telnet + # nc + # netcat + # busybox telnet + if [ -e "${TELNET:-does_not_exist}" ]; then + info"Will be using $TELNET as Telnet Client" + elif exists telnet ;then + TELNET="$(command -v telnet)" + elif exists nc ;then + TELNET="$(command -v nc)" + elif exists netcat;then + TELNET="$(command -v netcat)" + elif exists busybox;then + TELNET="$(command -v busybox) telnet" + else + error "Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.\nbailing out!" + return 1 + fi + $TELNET $@ +} + +send_irc(){ + ## reads from stdin, writes to IRC + ## + ## requires func: exists() anytelnet() + if [ -z "${HOSTN:-}" ]; then + HOSTN="$(get_hostname)" + info "no HOSTN given, using $HOSTN instead" + fi + IRCCHANNEL=${IRCCHANNEL:-"#krebs_incoming"} + IRCSERVER=${IRCSERVER:-"irc.freenode.net"} + IRCPORT=${IRCPORT:-6667} + NICK="${HOSTN}_$(head /dev/urandom | tr -dc "0123456789" | head -c3)" + info "starting irc connect as $NICK" + ( echo "NICK $NICK"; + echo "USER $NICK $IRCSERVER bla : $NICK"; + echo "JOIN $IRCCHANNEL"; + sleep 23; + while read line; do echo "PRIVMSG $IRCCHANNEL :$line";sleep 1;done + sleep 5; ) | anytelnet $IRCSERVER $IRCPORT 2>/dev/null | line_to_dot +} |