how to find mac address of a remote computer?

J

Jay

I need to write a program to find mac address of a remote computer, is
this possible? How?
 
M

Mark A. Odell

(e-mail address removed) (Jay) wrote in

I need to write a program to find mac address of a remote computer, is
this possible? How?

You cannot do this without platform-specific code which is off-topic here.
The C language does not provide networking support.
 
J

Jan Engelhardt

I need to write a program to find mac address of a remote computer, is
this possible? How?

Ping between both computers and run "arp" on one side if you got Linux or
similar.
 
D

Dan Pop

In said:
Ping between both computers and run "arp" on one side if you got Linux or
similar.

And you'll get the MAC address of the router, if the machines are not on
the same subnet.

Dan
 
L

Lew Pitcher

Jay said:
I need to write a program to find mac address of a remote computer, is
this possible? How?

#include <stdio.h>

int main(void)
{
char mac_address[257];

printf("Enter the MAC address of the remote computer: ");
fflush(stdin);

fgets(mac_address,sizeof(mac_address), stdin);
if (mac_address[strlen(mac_address) - 1] == '\n')
mac_address[strlen(mac_address) - 1] = 0;

printf("The MAC address of the remote computer is %s\n",
mac_address);

return 0;
}



--
Lew Pitcher

Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
 
J

Joona I Palaste

#include <stdio.h>
int main(void)
{
char mac_address[257];
printf("Enter the MAC address of the remote computer: ");
fflush(stdin);
^^^^^^^^^^^^^
Undefined behaviour. Because of this, the program might completely
fail to display the given MAC address.
fgets(mac_address,sizeof(mac_address), stdin);
if (mac_address[strlen(mac_address) - 1] == '\n')
mac_address[strlen(mac_address) - 1] = 0;
printf("The MAC address of the remote computer is %s\n",
mac_address);
return 0;
}

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Insanity is to be shared."
- Tailgunner
 
L

Lew Pitcher

Joona said:
^^^^^^^^^^^^^
Undefined behaviour. Because of this, the program might completely
fail to display the given MAC address.

Da*n, caught out by a typo. Of course, I meant
fflush(stdout);
but I transcribed it incorrectly.


--

Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
 
P

PeterW

Originally posted by Jay
I need to write a program to find mac address of a remote computer, is
this possible? How?



If you can run a remote shell on the machine, you can run ifconfig and
parse the result with grep from the standard output.


rsh remoteHost sbin/ifconfig | grep "^eth0"

eth0 Link encap:Ethernet HWaddr 00:0D:29:A8:80:44



You can use cut or awk to extract the MAC hardware address.
 
J

Joona I Palaste

PeterW said:
Originally posted by Jay
If you can run a remote shell on the machine, you can run ifconfig and
parse the result with grep from the standard output.
eth0 Link encap:Ethernet HWaddr 00:0D:29:A8:80:44
You can use cut or awk to extract the MAC hardware address.

Which part of this had anything at all to do with C?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top