MAC adresa
Peter Stibrany
cipso na ganga.gjh.schools.sk
Středa Červenec 15 10:42:29 CEST 1998
On Wed, 15 Jul 1998, Petr Pavlu wrote:
> Jak programove ( C ) zjistit HW ( MAC ) adresu sitove karty ?
> Ne pomoci ARP, ci pri startu :-))))
> -PP-
>
>
Tato cast kodu sa nedavno objavila v casopise Phrack, Volume 8, Issue 53
July 8, 1998 article 03 of 15. Trochu som to upravil aby sa to dalo
zkompilovat.
/* begin */
/*
* Sugestions and comments can be sent to author:
* Milos Prodanovic <azdaja na galeb.etf.bg.ac.yu>
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
int
main(int argc, char ** argv)
{
char c;
u_char mac[6] = "\0\0\0\0\0\0";
int nr = 0,eth_num = 0;
change_MAC(mac,eth_num);
return (0);
}
change_MAC(char *p, int ether)
{
struct ifreq devea;
int s, i;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
perror("socket");
exit(1);
}
sprintf(devea.ifr_name, "eth%d", ether);
if (ioctl(s, SIOCGIFHWADDR, &devea) < 0)
{
perror(devea.ifr_name);
exit(1);
}
printf("Current MAC is\t");
for (i = 0; i < 6; i++)
{
printf("%2.2x ", i[devea.ifr_hwaddr.sa_data] & 0xff);
}
printf("\n");
}
/* end */
Peter -Cipso- Stibrany
Další informace o konferenci Linux