This repository was archived by the owner on Oct 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy patharpMain.cpp
88 lines (68 loc) · 2.2 KB
/
arpMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;
#include "net\socket.h"
#include "net\InitWinsock.h"
#include "neo\CommandOptionParser.h"
#include "packet\InterfaceEnumerator.h"
#include "packet\PacketException.h"
#include "packet\PacketInterface.h"
#include "packet\iputils.h"
#include "packet\ARP.h"
/*
sendPacket (remoteIP)
{
localIP = local interface to use to send to remote host
if (remoteIP and localIP are on same subnet)
{
remoteMAC = ARP.whoHas (remoteIP)
sendPacket to remoteMac
}
else
{
gatewayIP = getGateway (localIP)
gatewayMAC = ARP.whoHas (gatewayIP)
sendPacket to gatewayMac
}
}
*/
int mainx(int argc, char* argv[])
{
net::InitWinsock initws (2,2);
packet::InterfaceEnumerator ie;
try
{
net::InetAddress gateway;
net::InetAddress local;
net::InetAddress remote(argv[1]);
packet::getRouteInfo(remote, local, gateway);
cout << "remote: " << remote << " local: " << local << " gateway: " << gateway << endl;
ie.findLocalInterfaces();
for (size_t n = 0; n < ie.getInterfaceCount(); n++)
{
const pcap_if_t& iface = ie.getInterface(n);
cout << iface.description << endl;
packet::ListAccessor<pcap_addr> addresses (iface.addresses);
for (size_t addrIndex = 0; addrIndex < addresses.getListLength(); addrIndex++)
{
pcap_addr* address = addresses.at(addrIndex);
net::InetAddress inetAddr(address->addr);
cout << inetAddr.getIPAddressAsString() << endl;
}
}
const pcap_if_t& iface = ie.getInterface(1);
packet::ListAccessor<pcap_addr> addresses (iface.addresses);
net::InetAddress localAddress(addresses.at(0)->addr);
packet::PacketInterface pac;
pac.openLocal(iface.name, 100, 50);
packet::ARP arp (pac);
net::InetAddress addr ("www.google.com");
packet::EthernetAddress macAddr;
arp.whoHas (localAddress, addr, macAddr);
cout << macAddr.toString() << endl;
}
catch (packet::PacketException& e)
{
cout << e.getMessage() << endl;
}
return 0;
}