?
Solved

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

Posted on 2007-10-17
1
Medium Priority
?
2,257 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:WinPE
1 Comment
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 20096184
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Introduction to Processes

579 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