How can I query the DNS server

I need to write a number of reports/cubes using the ISA log as the main source of data.

Unfortunately the ISA log only contains the IP address of the client computer and not it's name.
In order to determine the computer's name I (think) I need to read the DNS using the ip address as a key or search argument.

Does anyone know if this is possible or an easy way to determine a computers name from its IP address?

Ideally I woulld like to issue a query from an sql server stored procedure, but failing that a vb.net program.


Thanks in advance


Niall
 
niall_mooreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IQ150Commented:
Try this, it is a complete vb / asp solution, but you could scavenge what you need from here.

http://www.hexillion.com/samples/view_src.asp?name=NsLookup.inc.vbs.asp
0
fantasy1001Commented:
This is what you need:

HOW TO: Determine Computers Name from IP Address

Option Explicit

Private Const WSADescription_Len As Long = 256
Private Const WSASYS_Status_Len As Long = 128
Private Const WS_VERSION_REQD As Long = &H101
Private Const IP_SUCCESS As Long = 0
Private Const SOCKET_ERROR As Long = -1
Private Const AF_INET As Long = 2

Private Type WSADATA
  wVersion As Integer
  wHighVersion As Integer
  szDescription(0 To WSADescription_Len) As Byte
  szSystemStatus(0 To WSASYS_Status_Len) As Byte
  imaxsockets As Integer
  imaxudp As Integer
  lpszvenderinfo As Long
End Type

Private Declare Function WSAStartup Lib "wsock32" _
  (ByVal VersionReq As Long, _
   WSADataReturn As WSADATA) As Long
Private Declare Function WSACleanup Lib "wsock32" () As Long
Private Declare Function inet_addr Lib "wsock32" _
  (ByVal s As String) As Long
Private Declare Function gethostbyaddr Lib "wsock32" _
  (haddr As Long, _
   ByVal hnlen As Long, _
   ByVal addrtype As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (xDest As Any, _
   xSource As Any, _
   ByVal nbytes As Long)
Private Declare Function lstrlen Lib "kernel32" _
   Alias "lstrlenA" _
  (lpString As Any) As Long
 
Public Function SocketsInitialize() As Boolean
   Dim WSAD As WSADATA
   SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS
End Function

Public Sub SocketsCleanup()
   If WSACleanup() <> 0 Then
       MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation
   End If
End Sub

Public Function GetHostNameFromIP(ByVal sAddress As String) As String
   Dim ptrHosent As Long
   Dim hAddress As Long
   Dim nbytes As Long
   If SocketsInitialize() Then
     'convert string address to long
      hAddress = inet_addr(sAddress)
     
      If hAddress <> SOCKET_ERROR Then
        'obtain a pointer to the HOSTENT structure
        'that contains the name and address
        'corresponding to the given network address.
         ptrHosent = gethostbyaddr(hAddress, 4, AF_INET)
         If ptrHosent <> 0 Then
           'convert address and
           'get resolved hostname
            CopyMemory ptrHosent, ByVal ptrHosent, 4
            nbytes = lstrlen(ByVal ptrHosent)
            If nbytes > 0 Then
               sAddress = Space$(nbytes)
               CopyMemory ByVal sAddress, ByVal ptrHosent, nbytes
               GetHostNameFromIP = sAddress
            End If
         Else: MsgBox "Call to gethostbyaddr failed."
         End If 'If ptrHosent
      SocketsCleanup
      Else: MsgBox "String passed is an invalid IP."
      End If 'If hAddress
   Else: MsgBox "Sockets failed to initialize."
   End If  'If SocketsInitialize
End Function

'Usage
Private Sub Command1_Click()
   Text2.Text = GetHostNameFromIP(Text1.Text)
End Sub

~ fantasy ~

0
sirbountyCommented:
Not sure how fancy you want to get with it.
A simple PING -A 123.45.67.89 will resolve the IP address
Also,
NSLOOKUP 123.45.67.89 will resolve and deliver DNS server information.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

niall_mooreAuthor Commented:
What I want to do is for a given computer's ip address on my company's network determine the name of that computer.

IQ150 - none of the examples on that site do what I want to do.

Fantasy1001 - the code you present is VB6, whish I dont have access to - so I cannot test it

sirbounty - neither Ping nor NSLookup return what I want - Ping just tells me if a computer is logged on(in my case it may not be) and NSLookup works the other way round (it converts a name to an IP)
0
fantasy1001Commented:
Try this:

Private Function IPtoHost(ByVal IPstr As String) As String
Try
   Dim dns As System.Net.Dns
   Dim Host As New System.Net.IPHostEntry()
   Host = dns.GetHostByAddress(IPstr)
   IPtoHost = Host.HostName
Catch err As Exception
   MsgBox(err.Message)
End Try
End Function

~ fantasy ~
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyCommented:
Nslookup should work for you.  It queries the information stored in DNS.  If you run it against the IP address, it should give you the name.
The first line is the DNS server name, followed by its address.
The second line is the fully qualified name of the client, followed by its address (using this method - the address you supplied).
For instance - if the address I'm looking at is 192.168.0.43 and I ping it, I'll get a request timed out.
If I ping it with -a, I'll get the name of the host it's registered too, but 1 to 4 'Request timed out' (if I limit it by -n 1)
However, if I type
nslookup 192.168.0.43
I'll receive something like this: (whether the device is powered on or not)

Server: Alpha3.galaga.net
Address: 192.168.0.5

Name: Pod7.outerrealm.galaga.net
Address: 192.168.0.43

Maybe I'm not completely understanding your question?  Can you provide more detail?
Thanx
0
niall_mooreAuthor Commented:
Sirbounty - I have accepted Fantasy's answer as I want to be able to do this programatically but I tried nslookup as you suggest and I dont get similar results.
I get

Server:   [10.65.4.2]
Address: 10.65.4.2

but thanks for your help anyway
Niall
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.