Python3 use the socket to see the Web server programs used by the major websites to see which one is used the most.

Source: Internet
Author: User
Tags what web server

Use Python to send haeder/Then read the returned header information to see what Web server program the website is using.

This morning saw someone using Java to write a program like this, I use Python also a reality, originally wanted to put nginx not version of the count together, think not necessary. Results look at, or nginx more, followed by Apache, then IIS, Tengine This is also more Doha, should be counted as Nginx ha. Of course, there are also many companies with their own writing, such as Baidu's Bws,google GWS. There are also CWS and QWS.

#! /bin/pythonimport socket# counts the number of servers in a dictionary countdict = {"error": 0} #请求内容request = ' ' head/http/1.1accept: */*host:% (SIP ) sconnection:keep-alive ' #print (countdict) print ("{0:*^6}". Format ("HOST"), "{0:*^26}". Format ("WEB SITE"), "{0:*^6 } ". Format (" server: ")," {0:*^26} ". Format (" Server Name ")) Print ("-------------------------------------------------- ---------------") fp = open (' Serverlist.txt ', ' R ') for ServerIP in Fp:serverip = Serverip.strip () #print (Request% di        CT (sip = serverip)) #针对不同网站替换点请求的Host字段 TT = Request% dict (sip = ServerIP) #print (TT) #请求header try: s = socket.socket (socket.af_inet, socket. Sock_stream) S.connect ((ServerIP,)) S.send (Tt.encode ()) recv = S.recv (1024x768) recv = RECV.D        Ecode () #print (Recv.decode ()) except Timeouterror as Te:print ("HOST:", ServerIP, "Report Connection timeout error") countdict["Error"] =+ 1 print ("-----------------------------------------------------------------") continue    Except Exception as E:print ("HOST:", ServerIP, "reported unknown error") countdict["error"] =+ 1 print ("---- -------------------------------------------------------------") Continue #print (recv) recvlist = Recv.split ('            \ r \ n ') for a in recvlist: #if ' server: ' In A and A.startswith (' Server: '): If A.startswith (' Server: '): ServerName = A.split (': ') [1] #统计应用的服务器名了 if servername in Countdict:countdict[servername] + = 1 El Se:countdict[servername] = 1 #格式化打印 #print ("HOST:", ServerIP, "Server:", servername) print ("{0: <6}" . Format ("HOST:"), "{0: <26}". Format (ServerIP), "{0: <6}". Format ("Server:"), "{0: <26}". Format (ServerName)) p Rint ("-----------------------------------------------------------------") #打印统计结果print (countdict)

This is when there are only a few websites in Serverlist.txt.

This is after adding a lot of websites.

Python3 use the socket to see the Web server programs used by the major websites to see which one is used the most.

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.