tags:

views:

135

answers:

2

Hi, everyone. I am interested in making an HTTP Banner Grabber, but when i connect to a server on port 80 and i send something (e.g. "HEAD / HTTP/1.1") recv doesn't return anything to me like when i do it in let's say netcat..

How would i go about this?

Thanks!

+2  A: 

Are you sending a "\r\n\r\n" to indicate the end of the request? If you're not, the server's still waiting for the rest of the request.

Jon Skeet
I'll try it real quick. Just a minute.
Kaep
Thanks, it worked!
Kaep
How would i go about searching in the reply? If i want to make my script able to identyfy the, let's say content type, and print that out??
Kaep
@Kaep: Just to confirm, I'd suggest using an HTTP library of some form (whether urllib2 or anything else) rather than doing this yourself.
Jon Skeet
A: 

Try using the urllib2 module.

>>> data = urllib2.urlopen('http://www.example.com').read()
>>> print data
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  <META http-equiv="Content-Type" content="text/html; charset=utf-8">
  <TITLE>Example Web Page</TITLE>
</HEAD> 
<body>  
<p>You have reached this web page by typing &quot;example.com&quot;,
&quot;example.net&quot;,
  or &quot;example.org&quot; into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not available 
  for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt"&gt;RFC 
  2606</a>, Section 3.</p>
</BODY>
</HTML>

>>>

Asking for examples, you may miss finer points. To see the content-type header:

>>> stream = urllib2.urlopen('http://www.example.com')
>>> stream.headers['content-type']
'text/html; charset=UTF-8'
>>> data = stream.read()
>>> print data[:100]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  <META http-equiv=
>>>
gimel
How would i go about searching in the reply? If i want to make my script able to identyfy the, let's say content type, and print that out??
Kaep
See content-type example (addition). Actually, you need to look at BeautifulSoup - http://stackoverflow.com/questions/tagged/beautifulsoup
gimel