???????????????????????????÷?????????Щ??????????????????????????tcp/udpЭ???????????
????linux ?豸?????и????????????:
????/dev/[tcp|upd]/host/port ?????????д????????????????????????:host ????????????port?????????????????????????????socket ??????????/proc/self/fd?????棬?ж????????????
????????????£?/dev/tcp/host/post???
[chengmo@centos5 shell]$ cat</dev/tcp/127.0.0.1/22
SSH-2.0-OpenSSH_5.1
#??????shell??????22
#???:/dev/tcp???????????????????????????豸
[chengmo@centos5 shell]$ cat</dev/tcp/127.0.0.1/223
-bash: connect: ???????
-bash: /dev/tcp/127.0.0.1/223: ???????
#223??????????????
[chengmo@centos5 shell]$ exec 8<>/dev/tcp/127.0.0.1/22
[chengmo@centos5 shell]$ ls -l /proc/self/fd/
??? 0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 0 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 1 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 2 -> /dev/pts/0
lr-x------ 1 chengmo chengmo 64 10-21 23:05 3 -> /proc/22185/fd
lrwx------ 1 chengmo chengmo 64 10-21 23:05 8 -> socket:[15067661]
#?????????8??????????socket????????????????????дsocket???????????"<>"??
[chengmo@centos5 shell]$ exec 8>&-
#??????
[chengmo@centos5 shell]$ ls -l /proc/self/fd/
??? 0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 0 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 1 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 2 -> /dev/pts/0
lr-x------ 1 chengmo chengmo 64 10-21 23:08 3 -> /proc/22234/fd
????????????????
[chengmo@centos5 html]$ cat</dev/tcp/time-b.nist.gov/13
55491 10-10-22 11:33:49 17 0 0 596.3 UTC(NIST) *
????????????????????????????????????
?????????????????????web??????????
#!/bin/sh
#testhttphead.sh
#???????????????????web ??????header???
#copyright chengmo??qq:8292669
if(($
#<2));then
echo "usage:$0 host port";
exit 1;
fi
#????????????????????????1
exec 6<>/dev/tcp/$1/$2 2>/dev/null;
#??host??port ???д??socket????????????????6????
if(($?!=0));then
echo "open $1 $2 error!";
exit 1;
fi
#?????????$???????0?????????
echo -e "HEAD / HTTP/1.1 ">&6;
#??HEAD ??????????socket????
cat<&6;
#??socket??????????????????????
exec 6<&-;
exec 6>&-;
#???socket?????????
exit 0;
????????????????testhttphead.sh
???????н????
????[chengmo@centos5 ~/shell]$ sh testhttphead.sh www.baidu.com 80
????HTTP/1.1 200 OK
????Date: Thu?? 21 Oct 2010 15:17:23 GMT
????Server: BWS/1.0
????Content-Length: 6218
????Content-Type: text/html;charset=gb2312
????Cache-Control: private
????Expires: Thu?? 21 Oct 2010 15:17:23 GMT
????Set-Cookie: BAIDUID=1C40B2F8C676180FD887379A6E286DC1:FG=1; expires=Thu?? 21-Oct-40 15:17:23 GMT; path=/; domain=.baidu.com
????P3P: CP=" OTI DSP COR IVA OUR IND COM "
????Connection: Keep-Alive
????[chengmo@centos5 ~/shell]$ sh testhttphead.sh 127.0.0.1 8080
????open 127.0.0.1 8080 error!