VBSCRIPT: Perform Reverse NSLookup by computer's own ip.

I need to figure out a way to perform a reverse NS lookup by the computer's ip the script is running on. I also need to get the value minus the hostname from the lookup.

So nslookup 10.0.0.1
replied
hostname.contoso1.contoso.com
10.0.0.1

I need to grab the contoso1.contso.com and store it in a constant/variable.

I can't for the life of me figure this one out, can anyone help. I would like to do this in VB/VBscript if possible.
WinPEAsked:
Who is Participating?
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.

 
Shift-3Commented:
Here's my attempt, using code adapted from these articles:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct07/hey1012.mspx
http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1002.mspx

It should store the domain name in the variable strResult.


------------------
On Error Resume Next

strComputer = "."
strIP = "10.0.0.1"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objItem in colItems
    For Each objAddress in objItem.IPAddress
        arrIPAddress = Split(objAddress, ".")
        If arrIPAddress(0) <> 0 AND arrIPAddress(0) <> 169 Then
            strAddress = objAddress
            Exit For
        End If
    Next
    Exit For
Next

Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("nslookup " & strIP)
Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine
   If InStr(strLine,"Name:") Then
            arrLine = Split(strLine,".")
            intLimit = UBound(arrLine)
            For i = 1 To intLimit
                  strResult = strResult & arrLine(i)
                  If Not i = intLimit Then
                        strResult = strResult & "."
                  End If
            Next
    End If
Wend
0

Experts Exchange Solution brought to you by ConnectWise

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.