Announcement

Collapse
No announcement yet.

Ping

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ping

    Hallo Leute,

    ich brauche eine Funktion, der ich IP, Port und Dauer übergeben kann, mit dessen Hilfe die Funktion dann einen anderen Computer anpingen kann und wenn der Ping ankam, die Funktion einen true-Wert zurückliefert.
    Wenn sich jemand damit aus kennt, bitte helft mir. Danke.

  • #2
    Ah ja etwas hätte ich fast vergessen. Der Ping sollte über das TCP/IP Protokoll ausgeführt werden. Geht das überhaupt??? Wer kennt sich damit aus? Ich brauche wirklic Hilfe. CU

    Comment


    • #3
      hallo Timo Werner,

      so etwas hab ich mal programmiert, im kommentar steht auch woher es im orginal kommt kommt.
      nicht vergessen, icmp.lib (icmp.dll) zu benutzen. Durchsuche die festplatte mal nach den beiden header dateien.
      Bei BCB5 sollte es schon die icmp.dll von win2k sein sonst habe probleme selbst unter winnt. Über win9X kann ich nix sagen.
      mfg
      hmb

      extern "C" {
      #include "ipexport.h"
      #include "icmpapi.h"
      }

      //------------------------------------------------------------------------------
      // Name: Ping
      // ~~~~~ ~~~~~~~~~~~~
      // Comment: C++ Builder IV UNleashed Seite: 260
      // IN : API-Aufruf für Ping auf gegebene IP-Adresse
      // OUT: ---
      // RET: ---
      bool __fastcall Ping(int inIPAdress)
      {
      bool ret_val = true;
      HANDLE hIcmp = IcmpCreateFile();
      char* l_buff = NULL;
      // char l_SendePuffer[90]={'A'};

      if (!hIcmp) {
      ShowMessage("Unable to load ICMP.DLL. Could not Ping!!");
      return false;
      }
      try {
      try {
      int size = sizeof(icmp_echo_reply) + 8;
      l_buff = new char[size];

      DWORD res = IcmpSendEcho( hIcmp, inIPAdress, 0, 0, NULL, l_buff, size, 1000);

      if (!res)
      // timed out
      ret_val = false;
      else {
      icmp_echo_reply reply;
      memcpy(&reply, l_buff, sizeof(reply));
      if (reply.Status > 0)
      ret_val = false;

      }

      }
      //........................
      // Fehler:

      catch(Exception *exc){

      Tools->DisplayMess("ERROR",MB_OK | MB_ICONERROR,exc->Message.c_str(),"Ping");
      }
      }
      __finally {

      IcmpCloseHandle(hIcmp);
      if (l_buff)
      delete[] l_buff;

      }

      return ret_val;
      }

      //------------------------------------------------------------------------------
      // Name: MakeIPAddress
      // ~~~~~ ~~~~~~~~~~~~
      // Comment:
      // IN :
      // OUT: ---
      // RET: ---

      int __fastcall MakeIPAddress(String inIpAdress)
      {
      // Intialize Winsock.dll
      int ret_val = -1;
      WSADATA wsaData;
      memset(&wsaData, 0, sizeof(WSADATA));
      #pragma warn -prc
      Word lowVersion = MAKEWORD(2, 0);
      int res = WSAStartup(lowVersion, &wsaData);
      if (res) {
      ShowMessage("Unable to load Winsock. Could not Ping.");
      return ret_val;
      }
      // Is the address in IP format?
      ret_val = inet_addr(inIpAdress.c_str());

      if (ret_val == -1)
      {
      // Is the address a host name?
      hostent* he = gethostbyname(inIpAdress.c_str());

      if (!he)
      {
      int error = WSAGetLastError();
      ShowMessage("Winsock error: " + String(error));

      }
      else
      memcpy(&ret_val,
      he->h_addr_list[0], sizeof(int));
      }
      WSACleanup();
      return ret_val;
      }

      //und so wird´s aufgerufen:
      ...
      l_iIP = MakeIPAddress(tblIpConfigIPAdress->AsString);
      if (l_iIP>0)

      if (Ping(l_iIP)){
      ShowMessage("Pinging: " + tblIpConfigIPAdress->AsString + "-> OK!");
      }
      else
      {
      ShowMessage("Pinging: " + tblIpConfigIPAdress->AsString + "-> ???");
      }

      ..

      Comment


      • #4
        Viellen Dank für deine Unterstützung Hans Martin Brückmann.
        Ich muss das gleich heute Abend, wenn ich zu Hause bin ausprobieren.
        C

        Comment


        • #5
          Hallo Hans Martin,

          VIELEN DANK nochmals für die Funktionen, aber ich bekomme es einfach nicht hin. Ich finde nämlicgh die Includ-Dateien nirgends. Kann mir da jemand weiterhelfen, sodass ich die Funktionen mal testen kann??

          Comment

          Working...
          X