Solved

DNS

Posted on 1998-10-26
14
187 Views
Last Modified: 2010-04-30
Is there any way to input an IP address and have VB return that IP's hostname?
0
Comment
Question by:xlunax
  • 8
  • 6
14 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1441690
There is a function GetHostByAddr() function in Winsock.dll, but I'm not sure what kind of parameters it takes and what it returns.  I can experiment with it a little, and if I succeed, I'll post the code.

0
 
LVL 2

Expert Comment

by:shchuka
ID: 1441691
There is a function GetHostByAddr() function in Winsock.dll, but I'm not sure what kind of parameters it takes and what it returns.  I can experiment with it a little, and if I succeed, I'll post the code.

0
 
LVL 2

Accepted Solution

by:
shchuka earned 50 total points
ID: 1441692
I'm afraid you cannot use this function directly from a VB program, since it returns a pointer to a structure containing the information.  You'll need to write a C/C++ DLL that would perform the call and return the information in a VB accessible form.

The following is the description of this function:

The Windows Sockets gethostbyaddr function gets host information corresponding to an address.

struct hostent FAR * gethostbyaddr (

    const char FAR * addr,      
    int len,      
    int type      
   );      
 

Parameters

addr

[in] A pointer to an address in network byte order.

len

[in] The length of the address.

type

[in] The type of the address.

 

Remarks

gethostbyaddr returns a pointer to the following hostent structure which contains the name(s) and address which correspond to the given address. All strings are null terminated.

Return Values

If no error occurs, gethostbyaddr returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSANOTINITIALISED      A successful WSAStartup must occur before using this function.
WSAENETDOWN      The network subsystem has failed.
WSAHOST_NOT_FOUND      Authoritative Answer Host not found.
WSATRY_AGAIN      Non-Authoritative Host not found, or server failed.
WSANO_RECOVERY      Nonrecoverable error occurred.
WSANO_DATA      Valid name, no data record of requested type.
WSAEINPROGRESS      A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEAFNOSUPPORT      The type specified is not supported by the Windows Sockets implementation.
WSAEFAULT      The addr argument is not a valid part of the user address space, or the len argument is too small.
WSAEINTR      The (blocking) call was canceled through WSACancelBlockingCall.
 

See Also
0
 
LVL 2

Expert Comment

by:shchuka
ID: 1441693
I have written a small DLL that exposes a few functions like this.  You can download it from http://wtg.wharton.upenn.edu/~shchuka/Software/Hostname.zip
It does this function and some other ones (like the other way around: Hostname to IP, etc)

It includes enough documentation to get it to work in a few minutes.  I tested all the functions with VB and they work fine.

-Aleks.
0
 

Author Comment

by:xlunax
ID: 1441694
My VB5 wont find hostname.dll from yer site.  I tryed to reg it but It wont work.  Any ides?

0
 
LVL 2

Expert Comment

by:shchuka
ID: 1441695
Sounds strange... I will recheck it tomorrow morning, when I'm back at work, that's where I have the code.  Probably, I didn't link something statically and it's looking for some kind of run-time or something...

Again, I'll check it tomorrow...
0
 

Author Comment

by:xlunax
ID: 1441696
thanks alot..i also tryed to reference it...no luck
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Expert Comment

by:shchuka
ID: 1441697
Hi Xlunax,

Thanks for your patience.  I just uploaded a new version of that DLL to the same place.  Apparently, just what I said was the case.  I linked borland's runtime tynamically, thus, when you tried to use the dll, it was trying to find VCL35.bpl file and did not succeed.  I recompiled it with static linking.  It should be OK now.  Give it a try and let me know the outcome.

-Aleks.
0
 

Author Comment

by:xlunax
ID: 1441698
Well no it only finds the dll if its in windows\system dir but thats ok...but It crashes the second i call a function.
0
 

Author Comment

by:xlunax
ID: 1441699
This is exact message.  I tryed to use MSVC++ to debug but no luck.
---
VB5 caused an invalid page fault in
module HOSTNAME.DLL at 015f:01b1a6ad.
Registers:
EAX=00000000 CS=015f EIP=01b1a6ad EFLGS=00010246
EBX=0061eaa8 SS=0167 ESP=007ff1ec EBP=007ff1ec
ECX=007ff1f4 DS=0167 ESI=00000000 FS=3d5f
EDX=00000072 ES=0167 EDI=015c0eb0 GS=0e1e
Bytes at CS:EIP:
c6 00 00 8d 45 10 50 8b 55 0c 52 51 68 7c a6 b1
Stack dump:
007ff21c 01b11419 00000000 01b231d8 000000a8 000000bf 00000072 000000b3 007ff230 0063a95a 0063a9c4 bf72b3a0 007ff344 0fbdd74e 0061ea14 00000000


0
 
LVL 2

Expert Comment

by:shchuka
ID: 1441700
Strange... I created the dll with Borland C++ Builder 3.0 Pro.  I tested it with C++ and with VB - and everything wend smoth...  If you want to, give me your email address, and I'll send you the c++ source code.  You'll need to modify it a little bit to compile with visual c++.
0
 

Author Comment

by:xlunax
ID: 1441701
Well I found out why it crashed...in this line of code:
Public Declare Function IpToHostname Lib "Hostname.dll" (ByVal ip As String, ByVal host As String, ByVal hlen As Long) As Long

it says ByVal host as string, but if i dim a variable as a string it crashes.  If i done dim it a string it wont crash, but It still wont resolve the hostname at all.  If you can, write a simple program in VB5.0 that wil resolve an IP using your dll and send it to xlunax@rocketmail.com, maybe you can show me why its screwing up.
0
 
LVL 2

Expert Comment

by:shchuka
ID: 1441702
Actually - I did get it to crash - and the problem was in NOT preallocating the memory for the return string.  Here's how my procedure looked in my VB test project:

Private Sub cmdAddressToIp_Click()
    Dim host As String
    Dim res As Long
   
    host = String$(128, 0)
    res = IpToHostname(Text1.Text, host, 128)
    If res = 0 Then
        MsgBox "Error occurred", 16
    Else
        host = Left$(host, res)
        MsgBox "Hostname: " + host, 64
    End If
End Sub

In the meantime, I'll send you my zipped VB test project.

-Aleks.
0
 

Author Comment

by:xlunax
ID: 1441703
thanks alot it worked great
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now