News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to ping?

Started by Petroizki, March 09, 2005, 11:56:12 AM

Previous topic - Next topic

Petroizki

I don't have any network coding experience, so simple answers if possible..

I'm making an program that checks every 30 minutes, if an specific computer is online (192.168.0.1 in my LAN), and makes an log file, so i can slap our webmaster whenever it has been offline.

So.. The program itself is simple, but how can i make an simple ping, so i can see if the computer is currently online?

I tried IcmpSendEcho, but with no success..

Tedd

It was going to suggest sending data over port 7 (echo) but that will only work for a server (or a computer running a programming that listens on prot 7 and echos back.)

Pinging another machine on a LAN does work okay (just tried it) so I don't see why the IcmpSendEcho didn't work - although msdn recommends dynamically loading rather than linking to iphlpapi.dll or icmp.dll

You could always be crazy and try implementing it yourself :bg (but you'll need to open a raw socket)
http://www.ietf.org/rfc/rfc0792.txt?number=0792
No snowflake in an avalanche feels responsible.

Petroizki

Thanks,
I thought to give another try on IcmpSendEcho, and now it worked. I don't know what i did wrong last time. :red

Anyways, i'll put an simple test code here, if anyone ever finds it useful.

.386
.model flat, stdcall
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\ws2_32.inc

includelib kernel32.lib
includelib ws2_32.lib
.data
address db "192.168.0.1",0
icmp db "icmp.dll",0
icmpcreate db "IcmpCreateFile",0
icmpsend db "IcmpSendEcho",0
senddata db 32 dup (66h)
.data?
reply db (SIZEOF ICMP_ECHO_REPLY) + (SIZEOF senddata) dup (?)
.code
start:
invoke inet_addr, ADDR address
mov ebx, eax

invoke LoadLibrary, ADDR icmp

mov ebp, eax

invoke GetProcAddress, eax, ADDR icmpcreate

call eax ; IcmpCreateFile

mov edi, eax

invoke GetProcAddress, ebp, ADDR icmpsend

push 1000
push SIZEOF reply
push OFFSET reply
push NULL
push SIZEOF senddata
push OFFSET senddata
push ebx
push edi
call eax ; IcmpSendEcho

cmp eax, 0
je @error

; JIIHAAAAA! (ping was succesful)
int 3h

invoke FreeLibrary, ebp

invoke ExitProcess, 0
@error:
; ERROR..
int 3h
end start

James Ladd

Petroizki,
What assembler ru using ?
If its MASM then Im impressed you dont use the macros.
Rgs, striker

arafel

Quote from: Tedd on March 09, 2005, 01:17:55 PM
Pinging another machine on a LAN does work okay (just tried it) so I don't see why the IcmpSendEcho didn't work - although msdn recommends dynamically loading rather than linking to iphlpapi.dll or icmp.dll

What the reason behind this? Could you point to the msdn article please.

Petroizki

Quote from: striker on March 10, 2005, 02:16:10 AM
Petroizki,
What assembler ru using ?
If its MASM then Im impressed you dont use the macros.
Rgs, striker
MASM, but i actually just rewrote all that quickly for the public, because i always use my own invoke (and my own GetProcAddress)..

The original code was like this:
fncall GetProcOffset, eax, "IcmpCreateFile"

fncall eax ; IcmpCreateFile
mov edi, eax

fncall GetProcOffset, ebp, "IcmpSendEcho"

fncall eax, edi, ebx, OFFSET senddata, SIZEOF senddata, NULL, OFFSET reply, SIZEOF reply, 1000

Tedd

arafel

It's because different versions of windows have one or the other of those dlls.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho.asp (in the remarks)
No snowflake in an avalanche feels responsible.

liquidsilver

Thanx for this topic, I was having similar problems and hopefully not anymore :dance:, I'm so happy. I searched the net and nothing in Asm! i eventually resorted to starting a ping.exe process :lol!