Linux Network Test script

Source: Internet
Author: User
#! /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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.