On Thu, 2007-06-14 at 08:30 +0900, Reid Thompson wrote: > On Thu, 2007-06-14 at 07:45 +0900, wolfram wrote: > > > what operating system? windows/linux(distribution?)/osx? > > > how many network adapters are in the machine? > > > > Linux. > > > > > on windows use `ipconfig /all` and parse output or WMI through Win32OLE > > > on unix `/sbin/ifconfig -a` > > > > I know about the system commands. Is there a library/API to get these > > programmatically without having to parse output from a sytem command? > > > > Thanks, > > W. > > > Create a socket and pull it from the socket structure. > see if this works....???? rthompso@shienar ~ $ cat getnetmask.rb require 'rubygems' require "inline" class NetMask inline do |builder| builder.include '<sys/types.h>' builder.include '<sys/socket.h>' builder.include '<sys/ioctl.h>' builder.include '<netinet/in.h>' builder.include '<net/if.h>' builder.c " char * nmask() { int fd; struct ifreq ifr; fd = socket(AF_INET, SOCK_DGRAM, 0); ifr.ifr_addr.sa_family = AF_INET; strncpy(ifr.ifr_name, \"eth0\", IFNAMSIZ-1); ioctl(fd, SIOCGIFNETMASK, &ifr); close(fd); return (char *)inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); }" end end nm = NetMask.new() nmaa = nm.nmask() puts nmaa rthompso@shienar ~ $ ruby getnetmask.rb 255.255.255.0