ich habe ein eher seltsames problem mit select.select socket multiplexing.
Ich versuche, ca 100 pings parallel zu verschicken, klappt auch prima,
allerdings sind die empfangenen echo's alle die gleichen, bzw alle von 1-2 hosts.
Weiss jemand wieso es zu dem phenomen kommt?
hier hab ich das ganze nochmal extrem gekürzt und dirty neu geschrieben, selbes ergebnis wie die "richtige" variante.
In den prints sieht man das alle antworten von 1-2 ip's kamen statt ~ 100 verschiedene.
getestet auf Python 2.4.4 win32 / linux32
Code: Alles auswählen
from socket import *
import select
import time
ping_pkt = '\x08\x00\xb2\xe4\x12\x90\x00\x00 -HELLO HOST- -HELLO HOST- -HELLO HOST- -HELLO HOST- '
def ping1host(ip):
s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)
s.sendto(ping_pkt, (ip, AF_INET))
print s.recvfrom(512)
sockets = [socket(AF_INET, SOCK_RAW, IPPROTO_ICMP) for ip in ips]
for i, s in enumerate(sockets):
s.sendto(ping_pkt, (ips[i], AF_INET))
deadline = time.time() + timeout
while time.time() < deadline:
r, w, e = select.select(sockets, [], [], 0)
for s in r:
print s.recvfrom(512)
ips = [
# a few ip's (100)
]
if __name__ == '__main__':
ping1host('127.0.0.1')
ping_many(ips)