Jump to content

IP Resolver


MadBoy
 Share

Recommended Posts

What does it do:

This little tool detects problems between revDNS and DNS of a host. Sometimes when you do ping -a IP and ping -a HOST it doesn't match even thou it should. This happens because sometimes DHCP assings IP for too short time (either misconfigured or on purpose) and a new computer is getting IP of a computer that just disconnected from the network. This brings up many problems for programs like Altiris or other tools. This program takes a list of computer names from a file, tests them for the problem and gives output into .csv file with resutls.

What to set up:

Create --> resolving_input_file.txt -> create this file and put a list of computers you want to check for that problem

Modify --> $full_domain_extension -> to match your domain as in example in code

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\Project.ICONS\Info.ico
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Description=IP Resolver is tool to detect anomalities between revDNS and DNS.
#AutoIt3Wrapper_Res_Fileversion=0.5.0.0
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <file.au3>
#include <array.au3>
#include <string.au3>

Global $input_file = @ScriptDir & "\resolving_input_file.txt"
Global $output_file = @ScriptDir & "\resolving_output_file_" & @MDAY & "." & @MON & "." & @YEAR & "-" & @HOUR & "." & @MIN & "." & @SEC & ".csv"
Global $output_array[1]
Global $full_domain_extension = ".company.domain.com"

_ReadExternalComputerListFile($input_file)
MsgBox(262144,"Ip Resolver", "All tasks done successfully. Please check " & $output_file & " for results!")

Func _ReadExternalComputerListFile($file_to_read)
    Local $input_file_array
    Local $timer_start
    Local $timer_end
    Local $information_line
    
    If Not _FileReadToArray($file_to_read, $input_file_array) Then
        MsgBox(0, "Error 05", "Error reading input file " & $input_file)
    Else
        $file_output = FileOpen($output_file, 2)
        If $file_output = -1 Then
            MsgBox(0, "Error", "Unable to open " & $output_file & "file.")
        Else
            FileWriteLine($file_output, "Nr,Short Name, Full Computer Name,Resolved Name,Resolved IP,Test Result,Time to Execute" & @CRLF)
            For $x = 1 To $input_file_array[0]
                Local $computer_name = $input_file_array[$x]
                $timer_start = TimerInit()
                $information_line = _CheckIpResolving($computer_name)
                $timer_end = TimerDiff($timer_start) / 1000
                $timer_end = StringFormat("%.2f", $timer_end)
                FileWriteLine($file_output, $x & "," & $information_line & "," & $timer_end & @CRLF)
            Next
        EndIf
        FileClose($file_output)
    EndIf
EndFunc   ;==>_ReadExternalComputerListFile

Func _CheckIpResolving($name)
    Local $computer_name_short = $name
    Local $computer_domain_name = $name & $full_domain_extension
    Local $current_ip = "Not resolved"
    Local $current_dns = "Not resolved"
    Local $current_result = "Failed"
    $PingStatus = Run(@ComSpec & " /c ping -a -n 1 " & $computer_name_short, '', @SW_HIDE, 2)
    While 1
        $PingStatusData = StdoutRead($PingStatus)
        If @error Then ExitLoop
        If $PingStatusData Then
            If StringInStr($PingStatusData, "Pinging", 1, 1) <> 0 Then
                If StringInStr($PingStatusData, "[", 1, 1) <> 0 Then
                    $current_ip = _StringBetween($PingStatusData, "[", "]")
                    $current_ip = $current_ip[0]
                    $PingReverseStatus = Run(@ComSpec & " /c ping -a -n 1 " & $current_ip, '', @SW_HIDE, 2)
                    While 2
                        $PingReverseStatusData = StdoutRead($PingReverseStatus)
                        If @error Then ExitLoop
                        If $PingReverseStatusData Then
                            If StringInStr($PingReverseStatusData, "Pinging", 1, 1) <> 0 Then
                                If StringInStr($PingReverseStatusData, "[", 1, 1) <> 0 Then
                                    $current_dns = _StringBetween($PingReverseStatusData, "Pinging ", " [")
                                    $current_dns = StringLower($current_dns[0])
                                Else
                                    $current_dns = "Unable to resolve revDNS"
                                EndIf
                            EndIf
                        Else
                            Sleep(10)
                        EndIf
                    WEnd
                Else
                    $current_ip = "Unable to resolve DNS"
                EndIf
            EndIf
        Else
            Sleep(10)
        EndIf
    WEnd
    If $current_ip = "Not resolved" And $current_dns = "Not resolved" Then
    
        $full_line = StringLower($computer_name_short) & "," & StringLower($computer_domain_name) & "," & $current_dns & "," & $current_ip & "," & "CLIENT NOT RESPONDING"
    Else
        If $current_dns = "Unable to resolve revDNS" Then
            $full_line = StringLower($computer_name_short) & "," & StringLower($computer_domain_name) & "," & $current_dns & "," & $current_ip & "," & "REVERSE DNS FAILURE"
        Else
                        If $current_dns = $computer_domain_name Then
                $full_line = StringLower($computer_name_short) & "," & StringLower($computer_domain_name) & "," & $current_dns & "," & $current_ip & "," & "PASSED"
            Else
                $full_line = StringLower($computer_name_short) & "," & StringLower($computer_domain_name) & "," & $current_dns & "," & $current_ip & "," & "FAILED"
            EndIf
        EndIf
    EndIf
    Return $full_line
EndFunc   ;==>_CheckIpResolving

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...