Page 1 of 1 1
Topic Options
#14011 - 2001-11-07 06:27 PM GetHostByAddr
Anonymous
Unregistered


I want to translate an IP address into
a machine name so I can identify PC's
on our network
I know WSOCK32.DLL has something called
!gethostbyaddr, and I presume it can be
called by the new COM automation feature.
Unfortunately I have no idea how to do this

Top
#14012 - 2001-11-07 07:46 PM Re: GetHostByAddr
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Did some digging and found the following - http://www.vbapi.com/ref/g/gethostbyaddr.html

Looks reminiscent of Office VBA (Like MS-Access, for example). Other than that, on MSDN, I was able to find API structures which does not seem to fit this question.

Shawn/Bryce.. PING Shawn.. PING Bryce..

Have I totally lost it?

HTH,

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#14013 - 2001-11-07 08:53 PM Re: GetHostByAddr
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
working with the IP stack from a scripting language... is kinda in the hard side.

If you have one of MS's programming suites installed, then you can do it, otherwise, you have to install a 3rd party api control.

we went over this stuff in this thread here.
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002284

your best bet would be to shell out and do a ping command and grab the information that way.

code:

$ip = "208.169.161.27"

shell '%comspec% /c ping -a -n 1 -w 0 $ip | find /i "[$ip]" > %temp%\temp.txt'

$nul = open(1,"%temp%\temp.txt",2)
$data = readline(1)
$nul = close(1) del "%temp%\temp.txt"

$ipname = substr($data,9,instr($data,"[$ip]")-10)

? $ipname


Bryce

Top
#14014 - 2001-11-08 01:27 PM Re: GetHostByAddr
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I uploaded details of a working winsock implementation here, but as you will see it's not a simple business.

The ping / parse is a good solution.

I'll knockup a simple name resolution executable if you think it would be usefull.

Top
#14015 - 2001-11-08 05:01 PM Re: GetHostByAddr
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
AJH,

Ok, I've got a tiny (4k) executable which you can pass an IP address or hostname and it will return the IP address and FQDN.

If you still need this let me know and I will post instructions and a link that you can download the executable from.

If you are not keen on running the exe, I can let you have the source code and you can compile it up yourself.

Top
#14016 - 2001-11-08 07:56 PM Re: GetHostByAddr
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Be aware that in translating IP to host name, there are two posible names to resolve, the DNS name and the WINS name. They may be the same, but they may be different.

PING -A returns the DNS name
NBTSTAT -A returns the WINS name

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#14017 - 2001-11-09 11:59 AM Re: GetHostByAddr
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Correct up to a point.

TCP applications like PING prefer to resolve names by DNS. MS networking commands prefer to get names by WINS/broacast and other NETBIOS functionality but each method will eventually use the others resolution if it's preferred mode fails, it'll just take a while to get there.

There are (from memory) about 8 different ways to resolve host names, the only difference between NBTSTAT and PING is the order that these methods are used.

Fo instance I've just pinged my NETBIOS name "RICHARD HOWARTH". Now, I know it is not a valid DNS name, not least because my IP address is DHCP assigned and there is a space in it, but after a short delay the PING command happily resolved the name and pinged away.

Your warning should therefore be something like:
PING -A returns the DNS name by preference. If there is no DNS name PING may return the NETBIOS name.
NBTSTAT -A returns the NETBIOS name by preference.

I'm unsure if it is possible for NBTSTAT to have an unresolved IP address in it's tables.

Top
#14018 - 2001-11-09 03:34 PM Re: GetHostByAddr
Anonymous
Unregistered


Well however much I wanted a trivial solution, at least I know I havent asked
a stupid question!
Thanks for the offer Richard. I have seen a similar thing (probably on NONAGS), but I really wanted a UDF so that
everything is in the one file.
The Ping parsing solution therefore seems to be the one to go for.
(have you noticed that you can't use a DOS pipe symbol
in immediate mode, but it works in scripts - Weird?)

Top
#14019 - 2001-11-09 03:52 PM Re: GetHostByAddr
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Richard,
Thanks for elaborating, but that was not the point I was trying to raise. The point is that the DNS name and WINS (NETBIOS) name could very well be different.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2175 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.087 seconds in which 0.066 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org