Not sure the purpose. What better way would you like? An ipscan might do what you want, but you need to explain better what you want.
ew
I can look in /proc/net/arp, or parse the output
from ifconfig or dhclient, is there a better way?
Last edited by woodie; 07-19-2005 at 05:51 PM.
Not sure the purpose. What better way would you like? An ipscan might do what you want, but you need to explain better what you want.
ew
I want to know my own IP, so I can use it
in XML I have coming from a tivoweb module.
Code:#!/tvbin/tivosh proc get_ip_by_ifconfig {} { set ifconfig [exec "ifconfig"] set lines [split $ifconfig "\n"] set ip "" foreach l $lines { set raw [split [string trim $l] " "] if {[string compare [lindex $raw 0] "inet"] >= 0} { set addr [split [lindex $raw 1] ":"] if {[string compare [lindex $addr 0] "addr"] >= 0} { if {[string compare [lindex $addr 1] "127.0.0.1"] != 0} { set ip [lindex $addr 1] } } } } return $ip } puts [get_ip_by_ifconfig]
http://wiki.tcl.tk/3015Originally Posted by woodie
Note that a tivo may have more than one public ip address if it has more than one network adapter attached. If you are sure it is the eth0 address you want, this should work:The link shows some better ways.Code:% set myip [regexp -inline {\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}} [exec /sbin/ifconfig eth0]]
Last edited by Jamie; 07-19-2005 at 06:26 PM.
Hmm, that (above) didn't work for me.
Here is what I ended up with... same idea, fewer keystrokes.
It will return the first IP that isn't the loopback address.
Code:#!/tvbin/tivosh proc get_ip_by_ifconfig {} { foreach raw [split [exec "ifconfig"] " "] { if {[string match "addr:*" $raw]} { if {! [string match "*127.0.0.1" $raw]} { return [lindex [split $raw ":" ] 1] } } } } puts [get_ip_by_ifconfig]
I tested it and it worked on an S2. Not sure what would be different on an S1. The interface name? Notice I used a hardwired 'eth0'.Originally Posted by woodie
If you have a socket back to the host you are communicating with, there are better ways, as described in the link.
Last edited by Jamie; 07-19-2005 at 07:42 PM.
Yes, it seems like tivoweb should have an environment variableOriginally Posted by Jamie
that indicates which interface is communicatiing with the user.
I assume that the SA2 has more IP mojo. There is no place in the SA1 UI,
even the tivoweb UI, that indicates what IP address the tivo is on.
I noticed that my bogus TIVO_SVR_ADDR environment var
is also listed in this file. I wonder if they are valid in the SA2.
/tvlib/tcl/tv/Addr.itcl
Last edited by woodie; 07-19-2005 at 08:26 PM.
This is probably not the most efficient, but it works for me and you can do it all on one line. Just make sure you have grep and sed installed on your Tivo:
/sbin/ifconfig eth0 | grep "inet addr"| sed "s/ Bcas.*$//"|sed "s/^.*inet addr://"