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

Posted on 2007-10-17
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

I need to grab the 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.
Question by:WinPE
    1 Comment
    LVL 38

    Accepted Solution

    Here's my attempt, using code adapted from these articles:

    It should store the domain name in the variable strResult.

    On Error Resume Next

    strComputer = "."
    strIP = ""

    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
        Exit For

    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
        End If

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article will show, step by step, how to integrate R code into a R Sweave document
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now