Ping sans socket ou dns

Résolu
cs_cutch Messages postés 13 Date d'inscription samedi 10 mai 2003 Statut Membre Dernière intervention 14 mai 2007 - 14 mai 2007 à 11:02
cs_cutch Messages postés 13 Date d'inscription samedi 10 mai 2003 Statut Membre Dernière intervention 14 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.

Merci d'avance

Cutch

4 réponses

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
14 mai 2007 à 11:56
Tu peux l'utiliser via les APIS:
http://pinvoke.net/default.aspx/icmp/ICMPPing.html

<hr />
-Blog-
3
cs_cutch Messages postés 13 Date d'inscription samedi 10 mai 2003 Statut Membre Dernière intervention 14 mai 2007
14 mai 2007 à 12:51
Ok Merci ca m'as bien aidé

Voici un petit exemple que j'ai trouvé sur : http://www.msnewsgroups.net/group/microsoft.public.dotnet.languages.csharp/topic37596.aspx

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"));
     }
}

Cutch
3
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
14 mai 2007 à 11:42
Salut,
En utilisant la class Ping peut-être ?

<hr />
-Blog-
0
cs_cutch Messages postés 13 Date d'inscription samedi 10 mai 2003 Statut Membre Dernière intervention 14 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..."

Cutch
0
Rejoignez-nous