Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

c++ program, which detects a computer's IP and MAC address, using crafter.

  1. I downloaded and installed crafter library on my debian machine. The installation is as easy as described in libcrafter. The first example, which I tried, detects the computer's IP and MAC address. The code is simple and is listed below.

  2. #include <iostream>
    #include <string>
    #include <crafter.h>

    /* Collapse namespaces */
    using namespace std;
    using namespace Crafter;

    int main() {

      /* Set the interface */
      string iface = "eth0";

      /* Get the IP address associated to the interface */
      string MyIP = GetMyIP(iface);
      /* Get the MAC Address associated to the interface */
      string MyMAC = GetMyMAC(iface);

      cout << "My MAC address is : " << MyMAC << endl;
      cout << "My IP address is : " << MyIP << endl;

      return 0;
    }

  3. I used the following command to compile the code:
    g++ -g getIPandMAC.cpp -lcrafter

    The output is:
    pini@inbarvm:~/Home_2/PacketGen$ ./a.out
    My MAC address is : 00:1c:2a:b4:31:b0
    My IP address is : 192.168.2.155

  ...


Search This Site


Feedback This Site




new pages on this site