• Forum
  • Lounge
  • I am asking for codes and ideas [part II

 
I am asking for codes and ideas [part II]

Oct 11, 2015 at 4:39pm
closed account (28poGNh0)
Hiii everyone.
For the ones who know this thread http://www.cplusplus.com/forum/lounge/175384/
This is the second part of it.

I just resolved the problem but I want to benefice from it.
I want to write a program that does only one task.

Get the IP and the MAC of every device connected to my rooter either by Ethernet or wireless.

Thanks a lot.
Oct 11, 2015 at 4:56pm
Oct 12, 2015 at 6:03pm
Is this practical or academic OP? The practical answer is to ping broadcast then dump your arp table to a file. Academically, you'd be doing pretty much the same thing except with either BSD-style sockets, cURL, SFML or Boost::Asio. Pick one, let us know what OS you are using and then we can go from there.
Oct 12, 2015 at 11:27pm
closed account (28poGNh0)
It seems that you know a lot . You just wrote 3 lines and I barely understand 10% of it.

First of all(and hope for your understanding) What is the difference between practical or academic stuff,cuz I am not sure I know the real meaning of those tow words ?



Oct 13, 2015 at 2:35pm
I was wondering if you were looking for a practical solution, that is one that addresses your problem directly with the tools you already have on hand. Or if this question was academic in nature, where the practicality of the solution is not important and your goal is to learn about the code. Because this is in the lounge, I won't immediately assume that you are asking this question just to learn.

- Useful Information about the broadcast address : https://en.wikipedia.org/wiki/Broadcast_address
- ARP command line arguments for Windows: http://ss64.com/nt/arp.html
Last edited on Oct 13, 2015 at 2:36pm
Oct 13, 2015 at 7:26pm
Practically: Use SNMP. You should be able to pull a list of connected devices fairly easily. It's a little more accurate than ARP as the ARP table will contain devices that have recently disconnected.

Pinging broadcast may not work as devices can be configured to ignore that, and some routers will drop ping broadcasts.
Oct 14, 2015 at 1:34am
closed account (28poGNh0)
update
Last edited on Oct 14, 2015 at 2:09am
Oct 14, 2015 at 1:35am
ResidentBiscuit wrote:
... the ARP table will contain devices that have recently disconnected.


This part was intentional, I wanted something that would account for the possibility that the intruder may not be present when OP runs the test. Pinging broadcast is more of an update step then a query in this case.

SNMP is a perfectly valid option (actually it's just a protocol and it's a bit to ambiguous to be thought of as an actual solution here. But I'm pretty sure that I know where you're going with this and I won't steal your thunder), to be honest the reason that I didn't offer it here is because in the event that OP is running anything other than Windows I wouldn't have the faintest idea of where to begin much less how to go about it :/. Whereas the ping + ARP table solution I could BS my way through in just about any environment.

Ultimately I should point out that Duoas has already solved this issue in the previous thread: http://www.cplusplus.com/forum/lounge/175384/#msg867735 . The whitelist solution would prevent the intruder from connecting in the first place, making any attempt to detect them kind of a moot point.
Last edited on Oct 14, 2015 at 1:41am
Oct 14, 2015 at 2:09am
closed account (28poGNh0)
Thanks a lot for replying Mr @Computergeek01 and Mr @ResidentBiscuit

Well I can tell you now that this is a practical post ,I was gonna write it in General C++ Programming forum ,but I preferred that this thread's part2 stake up with the first part witch was in the lounge forum bla bla bla..

What I'm trying to do ,is filling four fields by four/one function(s) ,using c++ and other libraries if necessarily .

The "fields are"/"output is" :

HostName--------IP--------Mac Address--------Ethernet/wireless
=======--------==-------=========--------=============

MyRouter--------x.x.x.x--------x.x.x.x.x.x--------Router
My pc ------------x.x.x.x--------x.x.x.x.x.x--------Ethernet
Unknown--------x.x.x.x--------x.x.x.x.x.x--------Wireless


I want the code like this

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
struct HostNameInfo
{
    string HostNameName;// Weird name
    string HostNameIP;
    string HostNameMAC;
    char Ethernet_Wireless;
};

bool GetHostNameInfo(HostNameInfo &hni)// The magic fuction
{
    // Code
    hni.HostNameName = HostName;
    
    // code 
    hni.HostNameIP = HostIp;
    
    // code 
    hni.HostNameMAC = HostMac;
    
    // code 
    hni.Ethernet_Wireless = 'w';
}

int main()
{
    HostNameInfo myHNI;
    GetHostNameInfo(myHNI);
    
    /// Display myHNI
    
    return 0;
}


I found this function It's usefull but get me only the mac of my PC

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
# include <iostream>
# include <vector>
# include <windows.h>
# include <Iphlpapi.h>
using namespace std;

void getMacAddresses(void)
{
    IP_ADAPTER_INFO AdapterInfo[32];       // Allocate information for up to 32 NICs
    DWORD dwBufLen = sizeof(AdapterInfo);
    DWORD dwStatus = GetAdaptersInfo(AdapterInfo,&dwBufLen);

    //No network card? Other error?
    if(dwStatus != ERROR_SUCCESS)
    	return;

    PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;

    char szBuffer[512];

    while(pAdapterInfo)
    {
    	if(pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET)
    	{
    		wsprintf(szBuffer,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x"
    			, pAdapterInfo->Address[0]
    			, pAdapterInfo->Address[1]
    			, pAdapterInfo->Address[2]
    			, pAdapterInfo->Address[3]
    			, pAdapterInfo->Address[4]
    			, pAdapterInfo->Address[5]
    			);
    		cout << "The MAC address is : " << szBuffer << endl;
    	}
    	pAdapterInfo = pAdapterInfo->Next;

    }
}

int main()
{
    getMacAddresses();

    return 0;
}


Hope for your help
Topic archived. No new replies allowed.