1 |
Billy Holmes schrieb: |
2 |
> Alexander Skwar wrote: |
3 |
>> Don't like that - there might be locales, where there's no "inet" |
4 |
>> in the line. IMO better: |
5 |
>> /sbin/ifconfig eth0 | grep :255\. | cut -d : -f 2 | cut -d ' ' -f 1 |
6 |
> |
7 |
> broadcasts don't always begin or end with 255, odd yes, but if we're |
8 |
> spliting hairs then anything is possible. |
9 |
|
10 |
Well, I wasn't thinking about the *broadcast* adress (which |
11 |
in my address indeed has no 255 in it, as it is 192.168.1.31). |
12 |
I was referring to the network mask. Sure, even that doesn't |
13 |
*HAVE* to start with 255 - but I don't know about any network |
14 |
that "spans" multiple "class A" networks. |
15 |
|
16 |
But you're right, there's no requirement that the network |
17 |
mask MUST start with 255. It just happens to always and |
18 |
ever be that way - not so with the "inet addr" text. That |
19 |
happens to often be wrong (locale de_DE, fr_FR and certainly |
20 |
many others). |
21 |
|
22 |
> The only option is to assume that the address line appears on the 2nd |
23 |
> line, and it is delimited by a colon, and then strip out the fields past |
24 |
> the trailing spaces. |
25 |
|
26 |
Yep. Or that it is the 1st quad-dotted adress, or the 1st |
27 |
sequence of "numbers, maybe followed by dot" after the |
28 |
first colon, which would be a regexp approach. |
29 |
|
30 |
> /sbin/ifconfig eth0 | head -n 2 | tail -n 1 | cut -d : -f 2 | cut -d ' ' |
31 |
> -f 1 |
32 |
|
33 |
Nice. |
34 |
|
35 |
> and.. of course, this only works in linux... and for IPv4 Addresses. |
36 |
|
37 |
Yep. |
38 |
|
39 |
-- |
40 |
Alexander Skwar |
41 |
-- |
42 |
gentoo-user@g.o mailing list |