How to get IP address of PC?(Solved)

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

How to get IP address of PC?(Solved)

#1 Post by sunburnt »

I typed: env to get environment variables & I saw nothing that looked like an IP, ifconfig shows: 192.168.0.100
How do I get the assigned IP for the PC into an environment variable to use in Puppy startup scripts?
I assume Puppy is getting the IP from my router or dhcp-pxe boot server.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#2 Post by MU »

Add this line to one of the startupscripts:

MYIP=`ifconfig |grep "P-t-P"| sed "s/^.*addr://" | sed "s/\w.*//"`
export $MYIP

You can test it with
echo $MYIP >/tmp/iptest.txt

When puppy started, that file should contain your ip.
This is the IP you get assigned by your hoster using an internet-connection.
For the other ones, you might have to modify the command.

If you get stuck, please post the whole line you get with ifconfig, then we might help.

Mark

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#3 Post by GuestToo »

Code: Select all

IPADR=`wget http://ipid.shat.net/iponly/ -O /dev/stdout | head -n 3 | tail -n 1`

echo $IPADR

Guest

#4 Post by Guest »

I typed in the line just as you showed it, then the export line says: "not a valid identifier" on all the "|" pipes & the 3 "" statements.
Weard there isn't already a vari. for this, guess nothing needs it.

eth0 Link encap:Ethernet HWaddr 00:50:DA:71:1F:C8
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10381 errors:0 dropped:0 overruns:1 frame:0
TX packets:530 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3471943 (3.3 MiB) TX bytes:68737 (67.1 kiB)
Interrupt:11 Base address:0xe800

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#5 Post by GuestToo »

or

Code: Select all

IPADR=`wget -q "http://ipid.shat.net/iponly" -O - | sed -n 3p`

echo $IPADR

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#6 Post by GuestToo »

you can copy from the forum page by selecting the text with the mouse ... then paste in a rxvt console by clicking the middle mouse button

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#7 Post by GuestToo »

your local address is 192.168.0.100
to see your external address, click http://ipid.shat.net/iponly/

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#8 Post by sunburnt »

Sorry, I used ' instead of `, exports output is a list of the env vari.s saying: declare -x (vari. & it's value), echo returns nothing.
GuestToo; yours works, but I need the PCs net IP, not the web IP of my router.
I need to put IP in a env variable for boot script so many clients have Samba mount point for separate HOME automatically.
Example: smbmount //$IP_SRV/LanPup/$IP_CLI /mnt/home

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#9 Post by MU »

MYIP=`ifconfig |grep "Bcast"| sed "s/^.*addr://" | sed "s/\w.*//"`
export MYIP

This does:
run ifconfig
pipe (|) the result to grep
grep looks for the line with "Bcast"
So we have
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0

Next it is piped to sed, that filters everything from the beginning (^) to addr:
So we have
192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
Then again pipe through sed, filter the first whitespace (\w) and all after it (.*)
So we have
192.168.0.100

export MYIP might not be needed.
But on some system it assures, the variable is available in subshells, too.
(export $MYIP was wrong, don't use the $)

Mark
Last edited by MU on Thu 24 Nov 2005, 02:51, edited 1 time in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#10 Post by sunburnt »

THANKS MU!!! It works great! Above you had: export $MYIP, I wondered about that, but wasn't sure.
I got smbmount working so I think this is all coming together.
Thanks again, hope I can call on you again in the future.

User avatar
Rhino
Posts: 263
Joined: Wed 04 May 2005, 13:28
Location: Cincinnati, OH, USA
Contact:

#11 Post by Rhino »

A very simple method is to open Dillo and click the bookmark icon and then go to "What is my IP"

On second though, that may be more complicated than the command line stuff :-)

Post Reply