xterm下原始套接字可以接收數據包,但是發送數據包時出錯,怎麼解決?
錯誤是【error 101】network is unreachable.
代碼如下:
proto = socket.getprotobyname('tcp') # only tcp
sock = socket.socket( socket.AF_INET, socket.SOCK_RAW, proto )
packet_base = sock.recvfrom(1024)[0]
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(packet_base, ('123.123.123.123' , 12312))
從錯誤信息看,似乎是目標機器網絡不通。
看iptables有沒有阻止這個端口。