c++ program, which detects a computer's IP and MAC address, using crafter.
-
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.
-
#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;
}
-
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
|