How to get IP address of PC?(Solved)
How to get IP address of PC?(Solved)
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.
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.
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
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
Code: Select all
IPADR=`wget http://ipid.shat.net/iponly/ -O /dev/stdout | head -n 3 | tail -n 1`
echo $IPADR
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)
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)
or
Code: Select all
IPADR=`wget -q "http://ipid.shat.net/iponly" -O - | sed -n 3p`
echo $IPADR
your local address is 192.168.0.100
to see your external address, click http://ipid.shat.net/iponly/
to see your external address, click http://ipid.shat.net/iponly/
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
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
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
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.