Wgetcurlc view web Server Information

Source: Internet
Author: User
Article Title: wgetcurlc view web server information. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

A post from CU asked me how to view the web server information and suddenly remembered that I was quite curious.

[Root @ dbrg-2 ~] # Curl-I www.baidu.com

HTTP/1.1 200 OK

Date: Wed, 29 Jul 2009 02:51:19 GMT

Server: BWS/1.0.

Content-Length: 3509

Content-Type: text/html

Cache-Control: private

Expires: Wed, 29 Jul 2009 02:51:19 GMT

Set-Cookie: BAIDUID = 0D5F54C0853B7C38D6BD3A3E5EA63C44: FG = 1; expires = Wed, 29-Jul-39 02:51:19 GMT; path =/; domain = .baidu.com

P3P: CP = "oti dsp cor iva our ind com"

[Root @ dbrg-2 ~] # Wget-S -- spider www.baidu.com

-- 10:51:34 -- http://www.baidu.com/

=> 'Index.html

So the tool is implemented. How can we use c to implement it... in fact, it is also very simple. At the beginning, I also took a detour and thought about how to view the source code of wget or curl. But that code is too dependent on each other and it is not easy to read, so I used wireshark to capture packets, so easy !!!! Capture them if you are interested

# Include

# Include

# Include

# Include

# Include

# Include

# Include

# Define HTTPPORT 80

Char * head =

"HEAD/HTTP/1.0 \ r \ n"

"Accept: */* \ r \ n"

"User-Agent: Wget/1.10.2 (Red Hat modified) \ r \ n"

"Host: 127.0.0.1 \ r \ n"

"Connection: Keep-Alive \ r \ n ";

Int connect_URL (char * domain, int port)

{

Int sock;

Struct hostent * host;

Struct sockaddr_in server;

Host = gethostbyname (domain );

If (host = NULL)

{

Printf ("gethostbyname error \ n ");

Return-2;

}

[1] [2] Next page

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.