?? dev-tcp.sh
字號:
#!/bin/bash# dev-tcp.sh: 利用/dev/tcp重定向來檢查Internet連接. # 本腳本由Troy Engel編寫. # 經過授權在本書中使用. TCP_HOST=www.dns-diy.com # 一個已知的對垃圾郵件友好的ISP. TCP_PORT=80 # 端口80是http. # 嘗試連接. (有些像'ping' . . .) echo "HEAD / HTTP/1.0" >/dev/tcp/${TCP_HOST}/${TCP_PORT}MYEXIT=$?: <<EXPLANATIONIf bash was compiled with --enable-net-redirections, it has the capability ofusing a special character device for both TCP and UDP redirections. Theseredirections are used identically as STDIN/STDOUT/STDERR. The device entriesare 30,36 for /dev/tcp: mknod /dev/tcp c 30 36>From the bash reference:/dev/tcp/host/port If host is a valid hostname or Internet address, and port is an integerport number or service name, Bash attempts to open a TCP connection to thecorresponding socket.EXPLANATION if [ "X$MYEXIT" = "X0" ]; then echo "Connection successful. Exit code: $MYEXIT"else echo "Connection unsuccessful. Exit code: $MYEXIT"fiexit $MYEXIT
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -