[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: IP Address Variable?
- From: Hal Burgiss <hal foobox net>
- To: redhat-list redhat com
- Subject: Re: IP Address Variable?
- Date: Tue Jul 30 22:41:01 2002
On Wed, Jul 31, 2002 at 02:37:16AM -0000, Joe Giles wrote:
> Is there a preset variable in Linux that stores your IP address?
>
> I use DHCP, and I would like to use an IP variable (If one exists) to set my DISPLAY option... Can anyone help ?
>
> Example
>
> display=$MYIP:0;export display
>
> There $MYIP would be the actual Linux variable to export...
#!/bin/sh
#
## Extracts the current IP from ifconfig.
#
## usage: MY_IP=`my_ip` (with back quotes)
#
#######################################################################
#
#WAN_IFACE=ppp0
WAN_IFACE=eth0 #WAN Interface
# make sure the interface is up to start with ...
if ifconfig | grep $WAN_IFACE >/dev/null 2>&1 &&
ifconfig $WAN_IFACE |grep UP >/dev/null; then
# extract just our desired IP ...
ifconfig $WAN_IFACE | grep inet | cut -d : -f 2 | cut -d \ -f 1
exit $?
fi
exit 1
#--- eof my_ip
In your case, you might add:
else
echo localhost
===========
... just in case.
--
Hal Burgiss
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]