jji
package require Tclx
host_info addresses [info hostname]
(is there an easier way?)
-- Scott
Not easier, but different, the Scotty extension:
package require Tmn
set hostip [dns address $host]
With pure Tcl, you can get the IP after you connect to a TCP port
on the target hostname:
% set sock [socket www.scriptics.com 80]
% puts [fconfigure $sock -peername]
205.149.189.25 www.scriptics.com 80
Scotty is a way cool extension, if you're doing much in the way of
network programming, you'll want it. See FAQ for pointers to
source. Windows version exists for both TclX and Scotty.
--
Tom Poindexter
tpoi...@nyx.net
http://www.nyx.net/~tpoindex/
proc ipaddr { host } {
set testsock [socket $host 21]
set ipaddr [lindex [fconfigure $testsock -peername] 0]
set dnsName [lindex [fconfigure $testsock -peername] 1]
close $testsock
return $ipaddr ;# or return $dnsName
}
Otherwise I can point to the excellent scotty package, that you
can install for example from
http://wwwhome.cs.utwente.nl/~schoenw/scotty/ or
http://www.scriptics.com/resource/software/extensions/network/.
Scotty is a network management tool with SNMP,ICMP... and DNS.
Jochen.
Hmm. Do you have any reason for wanting to know what the IP address
is for a host without connecting to that host? (Many hosts have
several addresses anyway, and you're often best off not doing too much
with IP numbers if you can help it.)
Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ fell...@cs.man.ac.uk
-- The small advantage of not having California being part of my country would
be overweighed by having California as a heavily-armed rabid weasel on our
borders. -- David Parsons <o r c @ p e l l . p o r t l a n d . o r . u s>
There are all kinds of reasons to do such a thing, usually having to do
with comparing the IP numbers to something else.
- Are these two DNS names really the same machine?
- What are all the IP addresses assigned to that DNS name?
- Is this DNS name on the same network as that DNS name?
- Is that DNS name on the same network as I am?
- What should I do about this UDP-based protocol?
- Does the DNS name given in the SMTP HELO command match the IP address
the peer is connecting from?
- What are all the IP numbers assigned to this DNS domain, and can I
successfully ping any IP numbers that don't have names?
I would think SNMP and ICMP would both benefit from being able to do
such lookups.
Stuff like that.
This is getting off-topic, tho, so followups to me.
--
Darren New / Senior Software Architect / MessageMedia, Inc.
San Diego, CA, USA (PST). Cryptokeys on demand.