#!/bin/bash # Copyright (C) 2000 Tim Waugh # Licensed under the terms of the GNU General Public License v2 if [ "$1" = "--version" ]; then echo "Poor man's telnet 0.0.2"; exit 0 fi if [ "$1" = "--help" ]; then echo "Poor man's telnet: a simple telnet client written in bash." echo "usage: pmt " echo "This only really works for SMTP-style connections." exit 0 fi if [ -z $1 ]; then echo "Need hostname"; exit 1 fi if [ -z $2 ]; then echo "Need port"; exit 1 fi port=$2 if [ ! -z "${2##[0-9]*}" ] then port=$( (while read line; do line=${line#$2} line=$(echo ${line%%/tcp*}) if [ ! -z "$line" ]; then if [ -z "${line##[0-9]*}" ]; then echo $line break fi fi done ) < /etc/services) fi ( while :; do while :; do read line <&3 || exit 0 echo "$line" if [ ! -z "${line##???-*}" ]; then break; fi done read line; echo "$line" >&3 done ) 3<>/dev/tcp/$1/$port