| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
TCP_HOST=news-15.net |
| 8 |
TCP_PORT=80 |
| 9 |
|
| 10 |
|
| 11 |
echo "HEAD / HTTP/1.0" >/dev/tcp/${TCP_HOST}/${TCP_PORT} |
| 12 |
MYEXIT=$? |
| 13 |
|
| 14 |
: <<EXPLANATION |
| 15 |
If bash was compiled with --enable-net-redirections, it has the capability of |
| 16 |
using a special character device for both TCP and UDP redirections. These |
| 17 |
redirections are used identically as STDIN/STDOUT/STDERR. The device entries |
| 18 |
are 30,36 for /dev/tcp: |
| 19 |
|
| 20 |
mknod /dev/tcp c 30 36 |
| 21 |
|
| 22 |
>From the bash reference: |
| 23 |
/dev/tcp/host/port |
| 24 |
If host is a valid hostname or Internet address, and port is an integer |
| 25 |
port number or service name, Bash attempts to open a TCP connection to the |
| 26 |
corresponding socket. |
| 27 |
EXPLANATION |
| 28 |
|
| 29 |
|
| 30 |
if [ "X$MYEXIT" = "X0" ]; then |
| 31 |
echo "Connection successful. Exit code: $MYEXIT" |
| 32 |
else |
| 33 |
echo "Connection unsuccessful. Exit code: $MYEXIT" |
| 34 |
fi |
| 35 |
|
| 36 |
exit $MYEXIT |