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