cs_cutch
Messages postés13Date d'inscriptionsamedi 10 mai 2003StatutMembreDernière intervention14 mai 2007
-
14 mai 2007 à 11:02
cs_cutch
Messages postés13Date d'inscriptionsamedi 10 mai 2003StatutMembreDernière intervention14 mai 2007
-
14 mai 2007 à 12:51
Bonjour
Voila j'aimerai savoir comment je peu réaliser un ping sans utiliser les sockets, ou dns.
using System;
using System.Net;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct ICMP_ECHO_REPLY
{
public uint Address;
public uint Status;
public uint RoundTripTime;
public ushort DataSize;
public ushort Reserved;
public IntPtr Data;
public IP_OPTION_INFORMATION Options;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct IP_OPTION_INFORMATION
{
public byte TTL;
public byte TOS;
public byte Flags;
public byte OptionsSize;
public IntPtr OptionsData;
public int RealOptionData;
}
public class Icmp
{
public const int IP_SUCCESS = 0;
public const int IP_BUF_TOO_SMALL = 11001;
public const int IP_REQ_TIMED_OUT = 11010;
[DllImport("icmp.dll")]
public static extern IntPtr IcmpCreateFile();
[DllImport("icmp.dll")]
public static extern uint IcmpSendEcho(IntPtr icmpHandle, uint
ipAddr, ref int requestData, ushort requestSize, IntPtr optionInfo, ref
ICMP_ECHO_REPLY replyBuffer, uint replySize, int timeout);
[DllImport("icmp.dll")]
public static extern bool IcmpCloseHandle(IntPtr icmpHandle);
public static bool Ping(string host)
{
uint addr =
BitConverter.ToUInt32(IPAddress.Parse(host).GetAddressBytes(), 0);
IntPtr h = IcmpCreateFile();
int req = 123456789;
ICMP_ECHO_REPLY rep = new ICMP_ECHO_REPLY();
uint retval = IcmpSendEcho(h, addr, ref req, 4, IntPtr.Zero,
ref rep, 32, 10);
IcmpCloseHandle(h); return (retval !0 && rep.Status IP_SUCCESS);
}
}
public class TestClass
{
public static void Main(string[] args)
{
Console.WriteLine("min server : " + Icmp.Ping("192.168.1.10"));
Console.WriteLine("ikke eksisterende : " +
Icmp.Ping("192.168.1.25"));
Console.WriteLine("www.google.dk (svarer) : " +
Icmp.Ping("216.239.59.104"));
Console.WriteLine("www.eksperten.dk (svarer ikke) : " +
Icmp.Ping("62.199.138.148"));
}
}
cs_cutch
Messages postés13Date d'inscriptionsamedi 10 mai 2003StatutMembreDernière intervention14 mai 2007 14 mai 2007 à 11:49
lol
oui j'ai oublié de préciser que c'etait avec le framework 1.1 donc pas de class Ping.
J'aimerai pouvoir utiliser la dll 'icmp.dll' de windows , mais lorsque j'essaye de la rajouter dans mes reference, j'ai un message d'erreur " ..this is not a valid assembly or COM component..."