HTTP横幅抓取Python

时间:2010-06-19 16:27:55

标签: python netcat

我有兴趣制作HTTP Banner Grabber,但是当我连接到端口80上的服务器并且我发送了一些东西(例如“HEAD / HTTP / 1.1”)时,recv不会像我这样做时向我返回任何内容让我们说netcat ..

我该怎么做?

谢谢!

2 个答案:

答案 0 :(得分:2)

您是否发送了“\ r \ n \ r \ n”来表示请求的结束?如果不是,服务器仍在等待请求的其余部分。

答案 1 :(得分:2)

尝试使用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">RFC 
  2606</a>, Section 3.</p>
</BODY>
</HTML>

>>>

询问例子,你可能会错过更好的分数。要查看content-type标题:

>>> 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=
>>>