TCL for perl's gethostbyname?

1 view
Skip to first unread message

John Imholz

unread,
May 11, 1999, 3:00:00 AM5/11/99
to
What's the platform independent way of resolving a qualified internet
machine name to an IP address?

jji


Scott Redman

unread,
May 11, 1999, 3:00:00 AM5/11/99
to
Use the TclX extension, there is command "host_info":

package require Tclx
host_info addresses [info hostname]

(is there an easier way?)

-- Scott

Tom Poindexter

unread,
May 11, 1999, 3:00:00 AM5/11/99
to
In article <3738A705...@scriptics.com>,

Scott Redman <red...@scriptics.com> wrote:
>Use the TclX extension, there is command "host_info":
>
> package require Tclx
> host_info addresses [info hostname]
>
>(is there an easier way?)

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/

Jochen Loewer

unread,
May 12, 1999, 3:00:00 AM5/12/99
to
Using a socket and fconfigure -peername you can get the IP addr for a name
or the DNS name for an IP number., _if_ you have an open socket. So if
know a port on the target machine, which is listen to, it is easy. For example,
if you port 21:

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.

Donal K. Fellows

unread,
May 12, 1999, 3:00:00 AM5/12/99
to
In article <3738952C...@musc.edu>, John Imholz <imh...@musc.edu> wrote:
> What's the platform independent way of resolving a qualified
> internet machine name to an IP address?

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>

Darren New

unread,
May 12, 1999, 3:00:00 AM5/12/99
to
Donal K. Fellows wrote:
> Hmm. Do you have any reason for wanting to know what the IP address
> is for a host without connecting to that host?

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.

Reply all
Reply to author
Forward
0 new messages