Billy Holmes schrieb: > Alexander Skwar wrote: >> Don't like that - there might be locales, where there's no "inet" >> in the line. IMO better: >> /sbin/ifconfig eth0 | grep :255\. | cut -d : -f 2 | cut -d ' ' -f 1 > > broadcasts don't always begin or end with 255, odd yes, but if we're > spliting hairs then anything is possible.
Well, I wasn't thinking about the *broadcast* adress (which in my address indeed has no 255 in it, as it is 192.168.1.31). I was referring to the network mask. Sure, even that doesn't *HAVE* to start with 255 - but I don't know about any network that "spans" multiple "class A" networks. But you're right, there's no requirement that the network mask MUST start with 255. It just happens to always and ever be that way - not so with the "inet addr" text. That happens to often be wrong (locale de_DE, fr_FR and certainly many others). > The only option is to assume that the address line appears on the 2nd > line, and it is delimited by a colon, and then strip out the fields past > the trailing spaces. Yep. Or that it is the 1st quad-dotted adress, or the 1st sequence of "numbers, maybe followed by dot" after the first colon, which would be a regexp approach. > /sbin/ifconfig eth0 | head -n 2 | tail -n 1 | cut -d : -f 2 | cut -d ' ' > -f 1 Nice. > and.. of course, this only works in linux... and for IPv4 Addresses. Yep. -- Alexander Skwar -- [email protected] mailing list

