[ale] Get host's IP address as an unprivileged user?

James Sumners james.sumners at gmail.com
Mon Jun 6 10:25:36 EDT 2011


Hmm, the script is for some RHEL4 boxes. Doing `up2date
--show-available | grep ip` doesn't show the iproute2 package as even
being available (and I grep for 'ip' just to even get results).

Just to play around with the ip tool (as I had forgotten about it), I
checked on my Arch and Debian boxes. Looks like iproute2 is not
installed by default on Arch and it is installed by default on Debian.
But on Debian, `ip ls` is an invalid command. I believe `ip addr show
eth0` gives the results you're suggesting. The information listed
would require some more parsing than my original one :-/

I find it odd that it takes jumping through so many hoops just to get
the local (primary) IP address for scripting.

On Sat, Jun 4, 2011 at 2:24 PM, Michael Trausch <mike at trausch.us> wrote:
> $ ip ls
>
> You can grep for the if you're interested in. ip, from the iproute2 package,
> is the preferred mechanism for working with the networking stack in Linux;
> it is far more capable than ifconfig is.
>
> --
> Sent from my phone... a G2 running CM7 nightlies!
>
> On Jun 4, 2011 1:51 AM, "James Sumners" <james.sumners at gmail.com> wrote:
>> I need to get the IP address of the local machine on which a script is
>> being executed. The script is going to be run by an unprivileged user
>> (so /sbin is not in the PATH). Does anyone know of a better way than
>> this:
>>
>> IP=$(host $(hostname) | awk '{print $4}')
>>
>> --
>> James Sumners
>> http://james.roomfullofmirrors.com/
>>
>> "All governments suffer a recurring problem: Power attracts
>> pathological personalities. It is not that power corrupts but that it
>> is magnetic to the corruptible. Such people have a tendency to become
>> drunk on violence, a condition to which they are quickly addicted."
>>
>> Missionaria Protectiva, Text QIV (decto)
>> CH:D 59
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>



-- 
James Sumners
http://james.roomfullofmirrors.com/

"All governments suffer a recurring problem: Power attracts
pathological personalities. It is not that power corrupts but that it
is magnetic to the corruptible. Such people have a tendency to become
drunk on violence, a condition to which they are quickly addicted."

Missionaria Protectiva, Text QIV (decto)
CH:D 59


More information about the Ale mailing list