#! /Bin/sh #*********************************** ************************ # network test script # written by braincol 2011.04.06 #**** **************************************** *****************#********************** * ***************** # It takes too long for the commented out method to obtain the gateway! # Gateway = 'route | grep' default. * '| awk '1 {split ($0, parts ,""); print parts [2]} '# ****************************** * ******* gateway = 'cat/proc/NET/route | awk' function char2num (char) {dec = "0123456789"; # decimal Cap = "abcdef"; # capital min = "abcdef"; # minuscule if (length (char)> 1) {print "the length of the input char is erro! "; Return;} If (index (Dec, char)> 0) {return (index (Dec, char)-1);} else if (index (Cap, char)> 0) {return (index (Cap, char) + 9);} else if (index (Min, char)> 0) {return (index (Min, char) + 9);} else {# print "input char error! "Return 0 }} function str2ip (STR) {split (STR, out," "); Strout = sprintf (" % d. % d. % d. % d ", char2num (out [7]) * 16 + char2num (out [8]), char2num (out [5]) * 16 + char2num (out [6]), char2num (out [3]) * 16 + char2num (out [4]), char2num (out [1]) * 16 + char2num (out [2]); return Strout;} (FNR> 1) {split ($0, parts, "") if (parts [3]! = "00000000") {print str2ip (parts [3])} ''#************************************* * ***** # Too Many DNS records are obtained by the commented-out method, actually only one is enough. # nameserver = 'cat/etc/resolv. conf | grep 'nameserver. * '| SED's/^. * nameserver * // g ''#******************************* * ********** nameserver = 'cat/etc/resolv. conf | awk '(FNR <2) &/nameserver. */'| SED's/^. * nameserver * // g'' Internet = "www.baidu.com" Echo "Gateway:" $ gatewayecho "nameserver: "$ Nameserverecho" Internet: "$ internetecho" ------------------------------ "Ping-C 3 127.0.0.1>/dev/null 2> & 1if [" $? "! = "0"]; thenecho "network card does not work! "Elseecho" network card is OK! "Fi Ping-C 3 $ gateway>/dev/null 2> & 1if [" $? "! = "0"]; thenecho "can't connect to Gateway! "Elseecho" Gateway is connected! "Fiping-C 3 $ nameserver>/dev/null 2> & 1if [" $? "! = "0"]; thenecho "can't connect to DNS! "Elseecho" DNS is connected! "Fiping-C 3 $ Internet>/dev/null 2> & 1if [" $? "! = "0"]; thenecho "can't connect to the internet! "Elseecho" Internet is connected! "Fiexit 0