[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Get the ip address without using "root"?



On Fri, Aug 18, 2006 at 06:09:59PM +0800, Deephay wrote:

> How to get the address of the local machine without using "root"?
> ifconfig cannot be issued by a common user. TIA!

  Yes it can, the only problem is that by default /sbin will not be
 on the PATH of a non-root user.

  Just run it as follows:

skx@desktop:~$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:01:6C:ED:1A:51
          inet addr:192.168.1.40  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::201:6cff:feed:1a51/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  If you want the address something like this will work:

  /sbin/ifconfig eth0 | grep "inet addr"  | awk  '{print $2}'| awk -F: '{print $2}'

  eg:
skx@desktop:~$ IP=`/sbin/ifconfig eth0 | grep "inet addr"  | awk  '{print $2}'| awk -F: '{print $2}'`
skx@desktop:~$ echo ${IP}
192.168.1.40

  There are probably better ways, but that was the first thing that I tried..

Steve
-- 



Reply to: