#! /bin/sh
# Sets up a number of UDP connections thru a firewall
# on user-defined port(s). 
# args: target port [port port]
# dumps a bunch of data to the different ports on the target
# machine. You need to run the corresponding listen script
# on the target linux machine.
# Currently if you start outside the firewall put the 
# firewalls IP as the target. 

# Test to see if the correct arguments have been given
# if not then leave 

test ! "$1" && echo Usage: udp-load target port [port port] && exit 1
test ! "$2" && echo You must use at least one port argument  && exit 1

# Send the fake data and send the output to a file
# -n : use IP only no DNS -- we might want to add that
#      back in later
# -w 15 : waits 15 seconds, if nothing else comes in it exits
#         this will probably have to increase when going thru the firewall
# -u : sets it to UDP, it will be easy to change to test TCP
# -v : makes the output more verbose
# -i 1 : delays 1 sec after sending each line

echo Sending data.....
more README | nc -u -v -v -n -w 120 -i 1 "$1" "$2" >& "$1"."$2".output &

# Check if there were other port arguments
if test "$3" ;then
   more README | nc -u -v -v -n -w 15 "$1" "$3" >& "$3".output &
fi

if test "$4" ;then
   more probe | nc -u -v -v -n -w 15 "$1" "$4" >& "$4".output &
fi

# I'm not sure the if that's the best way to handle additional
# port arguments, but it will do the job. 

echo Udp-load script complete...
exit 0
 
