以更高的数据速率生成流量

时间:2014-03-18 15:12:26

标签: python network-protocols packet scapy traffic

from scapy.all import *
import socket 

s = socket.socket(socket.AF_INET, socket.SOCK_RAW,socket.IPPROTO_RAW)
s.bind(("127.0.0.1", 0))
pe=Ether()/IP(src="10.0.0.1",dst="10.0.0.2")/ICMP()
data = pe.build()
while True:
     s.send(data)

虽然我提到了目的地地址,但仍然使用此脚本我收到了此错误

WARNING: No route found for IPv6 destination :: (no default route?)

Traceback (most recent call last):

File "testing.py", line 12, in

s.send(data)

socket.error: [Errno 89] Destination address required

1 个答案:

答案 0 :(得分:0)

  1. 使用AF_PACKET代替AF_INET

    s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,socket.IPPROTO_RAW)
    
  2. 绑定到设备名称而不是地址。

    s.bind(("lo", 0))
    

    lo是环回设备名称。如果要将数据包发送到计算机外,请将其替换为实际设备名称。)