1

HTTPバナーグラバーの作成に興味がありますが、ポート80でサーバーに接続し、何か( "HEAD / HTTP / 1.1"など)を送信すると、recvは、たとえば、それを実行したときのように何も返しません。 netcat ..

どうすればいいですか?

ありがとう!

4

2 に答える 2

2

リクエストの終了を示すために「\r\ n \ r \ n」を送信していますか?そうでない場合でも、サーバーは残りのリクエストを待機しています。

于 2010-06-19T16:32:04.073 に答える
2

urllib2モジュールを使用してみてください。

>>> 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=
>>>
于 2010-06-19T16:37:30.437 に答える