Detection of network connectivity using shell script function

Source: Internet
Author: User

Typically, there are two ways to detect network connectivity for Linux systems:

1. Through "ping command + Destination IP" or "Ping + target IP domain"

Note IP network detection for IPV6 address need to try ping6, while ping6 can not use parameter hops, because the IP6 source has abandoned the route, see the following English explanation:

Synopsis
ping [-AABBDDFHLNOQRRUVV] [-C Count] [-f Flowlabel] [-I interval] [-I interface] [-l preload] [-m mark] [-M Pmtudisc_opti On] [-N nodeinfo_option]
[-W Deadline] [-w timeout] [-P pattern] [-Q TOS] [-S PacketSize] [-S SNDBUF] [-t TTL] [-t timestamp option] [Hop ...] Destinationt.
Notes:

Ping6 is IPv6 version of Ping, and can also send Node information Queries (RFC4620). Intermediate hops May is allowed, because IPV6 source
Routing was deprecated.

Common parameters for ping instruction invocation:

# Parameter:
#-C The number of packages to send
#-I internel between-packages
#-W Timeout seconds

# Check The Connect status of Internetfunction Check_ip_status () {    ping-c 3-i 0.2-w 3 $ &>/dev/null    If  [$?-eq 0];then        return 0    else        return-1    fi}if (' $ (check_ip_status 10.74.120.104)-ne 0 '); then    Echo "Cannot connect guestconf server:10.74.120.104"    Exit-1fi

2. Use "Curl Command + IP domain name"

    #!/usr/bin/bash      #      #检测网络链接 &&ftp upload data        function networkandftp ()        {            #超时时间            timeout=5                        #目标域名            target=www.baidu.com                    #获取响应状态码            ret_code= ' curl-i-S--connect-timeout $timeout $target-W%{ Http_code} | Tail-n1 '                    if ["X$ret_code" = "x200"]; then                #网络畅通            else                #网络不畅通            fi        

Detection of network connectivity using shell script function

Related Article

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.