nachdem der alte code für ein PING mit 3.94 nicht mehr ging, habe ich eine Lösung gesucht und gefunden. Allerdings nicht im deutschen Forum, deshalb stelle ich den code mal hier rein und beantworte damit selbst meine Frage. Wie pingt man mit 3.94?
Code: Alles auswählen
;PING (with 3.94)
;(die Korrektur des PING ist von mark aus dem englishen Forum)
;(der Rest sind Funktionen die ich öfters brauche)
InitNetwork()
;check if IP$ is valid
Procedure.l isip(param.s)
v.l=0
For i=1 To 4
v=Val(StringField(param,i,"."))
If v<1 Or v>255 : ret=0 : Else : ret=1 : EndIf
Next
ProcedureReturn ret
EndProcedure
;convert IP$ to IP
Procedure.l ipval(ip$)
ip.l
ab1=Val(StringField(ip$,1,"."))
ab2=Val(StringField(ip$,2,"."))
ab3=Val(StringField(ip$,3,"."))
ab4=Val(StringField(ip$,4,"."))
ip=MakeIPAddress(ab1,ab2,ab3,ab4)
ProcedureReturn ip
EndProcedure
; DNS reverse lookup
Procedure.s ip2fqdn(ip.l)
ret$=""
*host.hostent=gethostbyaddr_ (@ip,4,2)
If *host<>0
ret$=PeekS(*host\h_name)
Else
ret$=""
EndIf
ProcedureReturn ret$
EndProcedure
; DNS resolve hostname
Procedure.l host2ip(host$)
ret.l=0
*host.hostent=gethostbyname_ (host$)
If *host<>0
ret=(PeekL(PeekL(*host\h_list)))
Else
ret=*host
EndIf
ProcedureReturn ret
EndProcedure
; PING ip
Procedure Ping(ipAddress.l)
#PING_TIMEOUT = 1000
#PING_LOOP = 3
EchoMessage.s = "ping echo message"
ResultSize.l = SizeOf(ICMP_ECHO_REPLY) + Len(EchoMessage)
*Result = AllocateMemory(ResultSize)
*Echo.ICMP_ECHO_REPLY = *Result
ret.l=0
hFile.l = IcmpCreateFile_()
For loop = 1 To #PING_LOOP
lngResult.l = IcmpSendEcho_(hFile, ipAddress, EchoMessage, Len(EchoMessage), 0, *Result, ResultSize, #PING_TIMEOUT)
If lngResult
ret+1
Delay(300)
rtt=rtt+*Echo\RoundTripTime
EndIf
Next
IcmpCloseHandle_(hFile)
FreeMemory(*Result)
If ret : ret=rtt/ret : Else : ret=-1 : EndIf
ProcedureReturn ret
EndProcedure
;-main
;from name to ip and ping
Debug "ping www.google.com"
name$="www.google.com"
If isip(name$)
ip=ipval(name$)
ip$=IPString(ip)
host$=ip2fqdn(ip)
rtt=Ping(ip)
Else
host$=name$
ip=host2ip(host$)
ip$=IPString(ip)
rtt=Ping(ip)
EndIf
Debug host$
Debug ip$
Debug Str(rtt)+" ms"
Debug " "
;from ip to name and ping
Debug "ping Yahoo"
name$="216.109.112.135"
If isip(name$)
ip=ipval(name$)
ip$=IPString(ip)
host$=ip2fqdn(ip)
rtt=Ping(ip)
Else
host$=name$
ip=host2ip(host$)
ip$=IPString(ip)
rtt=Ping(ip)
EndIf
Debug host$
Debug ip$
Debug Str(rtt)+" ms"
Michael
Habs mal verschoben da es hier besser aufgehoben ist

Gruß,
Nico