How do I get the Serial # of my CPU ?
Rod Stephens
krs0 at GTE.COM
Mon Oct 15 21:12:52 AEST 1990
In article <1263 at ixos.de> snoopy at ixos.de writes:
>Dear Net,
>
>would like to get at the serial number (not the CPU Type) of my
>DEC machine (DECStation or uVax) from a C-Program.
I don't think this can be done (I would love to hear that it can) but
you can get your CPU ethernet address. I am told that this address can
be changed but it probably won't be. The following code was posted
some time ago -- sorry I don't remember who posted it so I cannot give
them proper credit.
+---------------------------------------------------------------+
| Rod Stephens | "Haven't I told you not to play |
| GTE Laboratories, Inc | with my super-weapons? You might |
| (617)466-4182 | devastate yourself!" |
| krs0 at gte.com | |
+---------------------------------------------------------------+
-- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE -- CUT HERE --
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <net/if.h>
extern int errno;
main(ac, av)
int ac;
char *av [];
{
int s;
char *line = "------------------------------------";
char device [IFNAMSIZ+1];
/* structure used to query de and qe for physical addresses
struct ifdevea {
char ifr_name[IFNAMSIZ];
char default_pa[6];
char current_pa[6];
};
*/
struct ifdevea hw_addr;
s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
perror ("socket:");
exit (3);
}
if (ac > 1 && strlen (av [1]) <= IFNAMSIZ)
strcpy (&hw_addr.ifr_name [0], av [1]);
else strcpy (&hw_addr.ifr_name [0], "se0");
if (ioctl(s, SIOCRPHYSADDR, (caddr_t) &hw_addr) < 0) {
perror ("ioctl: SIOCRPHYSADDR");
close(s);
exit (1);
}
printf ("\n%s\n", line);
printf ("addresses for %s :\n", &hw_addr.ifr_name [0]);
printf ("%s\n", line);
print_addr ("hardware-address", &hw_addr.default_pa [0]);
print_addr ("current-address ", &hw_addr.current_pa [0]);
printf ("%s\n", line);
close(s);
}
print_addr (what, ether_addr)
char *what, *ether_addr;
{
printf ("%s = %02x-%02x-%02x-%02x-%02x-%02x\n", what,
ether_addr [0] & 0xff,
ether_addr [1] & 0xff,
ether_addr [2] & 0xff,
ether_addr [3] & 0xff,
ether_addr [4] & 0xff,
ether_addr [5] & 0xff);
}
More information about the Comp.unix.ultrix
mailing list