How to detect if a domain name or URL is properly parsed and transmitted in one click

Source: Internet
Author: User

Long time no blog, and now pick up, I think it is not too late.

At work, people often complain: the website is good card, DNS is not a problem ... Is there a one-click approach to the problem of DNS resolution or is it caused by network transmission?

Yes. You can write some script checks. The shell can make full use of the Curl tool to write scripts, and Python can make full use of the Pycurl module script.

#!/usr/bin/env python#coding: utf-8 "function: Detection of domain name resolution and URL response time usage: You can write the relevant domain name or URL to die, you can also modify the script to become interactive, each can detect a number of any small  e-mail: [email protected] Version: v1.0 time: 2018.07.19 "import sysimport osimport  timeimport pycurl# #urls  =  "https://www.baidu.com" Urls = raw_input ("Please input  your urls:  ") If len (URLs)  == 0:    print (" You have  no input any url ")     sys.exit (1) print (" ") for url in  urls.split ():     c = pycurl. Curl ()     c.setopt (Pycurl. Url, url)     c.setopt (Pycurl. connecttimeout, 5)     c.setopt (Pycurl. timeout, 5)     c.setopt (Pycurl. forbid_reuse, 1)     c.setopt (Pycurl. maxredirs, 1)     c.setopt (Pycurl. noprogress, 1)     c.setopt (Pycurl. Dns_cache_timeout, 30)         indexfile = open (os.path.dirname (Os.path.realpath (__file__))  +  "/content.txt",  "WB")     c.setopt (Pycurl. Writeheader, indexfile)     c.setopt (Pycurl. Writedata, indexfile)         try:         c.perform ()     except Exception, e:         print ("connection error: "  + str (e))          indexfile.close ()         c.close ()          sys.exit ()         namelookup_time =  c.getinfo (c.namelookup_time)     connect_time = c.getinfo (C.CONNECT_TIME)     pretransfer_time = c.getinfo(c.pretransfer_time)     starttransfer_time = c.getinfo (C.STARTTRANSFER_TIME)     total_time = c.getinfo (c.total_time)     http_code =  c.getinfo (C.http_code)     size_download = c.getinfo (C.SIZE_DOWNLOAD)      header_size = c.getinfo (c.header_size)     SPEED_DOWNLOAD  = c.getinfo (c.speed_download)         print ("-" *15 + url  + "-" *15)     print ("HTTP Status code:%s"  %  (http_code))     print ("DNS resolution Time:%.2f ms"  %  (namelookup_time * 1000))     print ("Establish connection time:% .2f ms  " %  (connect_time * 1000))     print (" Ready to transfer time:%.2f  ms  " %  (pretransfer_time * 1000))     print (" Transfer start time:%.2f  ms  " %  (starttransfer_time * 1000))     print ("Transfer End time:%.2f ms "  %   (total_time * 1000)     print ("Download packet size:%d bytes/s "  %  (Size_download))     print ("HTTP header size:%d byte "  %  (header_size))      Print ("Average download speed:%d bytes/s "  %  (speed_download))     print ("") Indexfile.close () C.close () Sys.exit ()

Above I use Python to write a key detection script, the script can be named: mypycurl.py, Execution: Python mypycurl.py, detection can write 1 or more. The results of the implementation are as follows:

By executing the results, we can see the parsing time of the domain name, the network transmission time, the download speed, etc., these results are fully utilized Pycurl module analysis. You can perform more than one test, or the script J plus a For loop, 10 times per loop, if the DNS resolution time is longer (for example, each time is more than 100 ms), then there is a problem with DNS, then the right remedy.


About the script in the module, method or Python syntax, if you do not understand the place can Baidu, can also give me a message, as long as I see a certain answer questions, common progress!


How to detect if a domain name or URL is properly parsed and transmitted in one click

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.