[Techtalk] When might I use 'hostid'?
Kai MacTane
kmactane at GothPunk.com
Tue Mar 5 20:13:21 EST 2002
At 3/5/02 05:28 PM , hobbit at aloss.ukuu.org.uk wrote:
>And this sounded useful (except for the bit about the answer
>being in hex). Trying it, I got
>
>[hobbit at aloss hobbit]$ hostid
>7f0100
I tried it out myself, thinking I could probably answer this pretty easily.
The machine I was trying it on is multi-homed, having IP addresses:
64.81.50.196
64.81.50.197
64.81.50.198
When I ping things from it, the ping usually comes from .198, so I suspect
that's what hostid will return.
Now, 64, 81, 50, and 198 expressed in binary would like these:
01000000
01010001
00110010
11000110
and if you string them together as a single huge binary number, you get:
01000000010100010011001011000110
Converting this into hex gets me 405132C6, and that's what I think I should
expect to see out of hostid. Unfortunately, when I run it, I get 5140c632
instead, which is nowhere close.
Converting 5140c632 back into binary and breaking it up into 8-bit bytes to
see what the hell hostid thinks my IP address is, I get the four bytes:
01010001
01000000
11000110
00110010
Which translates to: 81.64.198.50. Joy. Why it scrambled the bytes, I have
no idea.
However, that does mean I can do some arithmetical gymnastics with your
result, 7f0100. (I'll presume there must be a bunch of leading zeroes on
there.) Actually, screw it -- from here, I'll take a quick jump on the
basis of the "7f", the "00" and the "01" in there, and say it's returning
your loopback address: 127.0.0.1. (Except in scrambled order, as 0.127.1.0,
so the leading zeroes go away.) This also explains why so many other people
got the same result: the loopback address is universal.
>What is this command for? When would I need to use it? Is it a
>"handy for shell scripts when put within back-ticks" thing?
Probably. I think it's the sort of thing you'd feed to functions, modules,
or other programming structures that expect to get an IP address in hex. (I
think there are some networking functions in the standard C libraries that
work that way.) Why the bytes are switched around, I have no idea.
--Kai MacTane
----------------------------------------------------------------------
"And when I squinted/The world seemed rose-tinted;
Angels appeared to descend..."
--Depeche Mode,
"Waiting for the Night"
More information about the Techtalk
mailing list