Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3652
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2017-02-27 17:34
文章分类

全部博文(1)

文章存档

2017年(1)

我的朋友
最近访客

分类: Python/Ruby

2017-03-02 09:47:57

import socket,time
#coding:UTF-8
#发送的http包头
header_send='GET / HTTP/1.1\r\nHost: \r\nConnection: close\r\n\r\n'
i=0
#请求次数
num=10
#请求间隔
tinktime=1
#目的地址
ip_dst='192.168.5.202'
#目的端口
port_dst=80
while i<10:
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip_dst,port_dst))
s.send(header_send)
buffer = []
while True:
   # 每次最多接收1k字节:
   d = s.recv(1024)
   if d:
       buffer.append(d)
   else:
       break
data = b''.join(buffer)
s.close()
header, html = data.split(b'\r\n\r\n', 1)
print(header.decode('utf-8'))
# 把接收的数据写入文件:
#with open('sina.html', 'wb') as f:
   #f.write(html)
#i=i+1
#time.sleep(tinktime)

阅读(1791) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~