Jump to content

Hostname Enumerator (... best I can think of)


Mechaflash
 Share

Recommended Posts

Because sharing is caring...

#include <Constants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>

Global $hGUI, $aControls[5], $sFile
Local $sLabel, $sButton, $aOutput, $sBrowse, $sLabel1, $sLabel2

$hGUI = GUICreate("Network Enumerator", 400, 140)
GUICtrlCreateGroup(" |     IP Network Octets      |   IP Subnet   |   IP Range  |  ", 10, 10, 380, 90)
$aControls[0] = GUICtrlCreateInput("192",     30,                             50, 50, 20, BitOr($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$aControls[1] = GUICtrlCreateInput("168",     30 + 50 + 10,                     50, Default, Default, BitOr($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$aControls[2] = GUICtrlCreateInput("0",     30 + (50 + 12) * 2,             50, Default, Default, BitOr($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$aControls[3] = GUICtrlCreateInput("1",     30 + (50 + 13) * 3,             30, Default, Default, BitOr($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$aControls[4] = GUICtrlCreateInput("255",     30 + (50 + 13) * 3,             65, Default, Default, BitOr($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$sLabel1 = GUICtrlCreateLabel("Start" & @CR&@CR & "End", 30 + (50 + 13) * 4, 30, 50, 55)
$sButton = GUICtrlCreateButton("GO!", 30 + (50 + 10) * 5,                    35, 50, 50)
$sLabel2 = GUICtrlCreateLabel("Output File: ", 10, 120, 60, 20)
$sFile = GUICtrlCreateInput(@DesktopDir & "HostList.txt", 80, 115, 250, 20)
$sBrowse = GUICtrlCreateButton("Browse", 340, 115, 50, 20)
GUICtrlSetColor($sLabel1, 0x0000FF)
GUICtrlSetColor($sLabel2, 0x0000FF)
GUICtrlSetFont($sLabel1, 12)
For $i = 0 To 4
    GUICtrlSetLimit($aControls[$i], 3)
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sButton
            GUISetState(@SW_HIDE)
            ProgressOn("Building Host List", "Enumerating Given IP Range", "", Default, 300, 1 + 16)
            _EnumerateIPs()
            GUISetState(@SW_SHOW)
        Case $sBrowse
            GUISetState(@SW_HIDE)
            $sSelectedFile = FileOpenDialog("Select Output File", @DesktopDir, "Text Files (*.txt)", 8, "HostList.txt")
            If Not @error Then GUICtrlSetData($sFile, $sSelectedFile)
            GUISetState(@SW_SHOW)

    EndSwitch
WEnd

Func _EnumerateIPs()
    Local $iStart, $iFinish, $sBaseIP = ""
    For $i = 0 To 2
        $sBaseIP&= GUICtrlRead($aControls[$i]) & "."
    Next
    $hFile = FileOpen(GUICtrlRead($sFile), 1)
    $iStart = GUICtrlRead($aControls[3])
    $iFinish = GUICtrlRead($aControls[4])
    For $i = $iStart to $iFinish
        If $i = 0 Then ContinueLoop
        ProgressSet($i / $iFinish * 100, "Scanning " & $i & " of " & $iFinish - $iStart + 1 & " IPs." & @CRLF & $sBaseIP & $i, "Enumerating Given IP Range")
        FileWrite($hFile, $i & "|" & _HostnameFromIP($sBaseIP & $i) & "|" & $sBaseIP & $i & @CRLF)
    Next
    FileClose($hFile)
    ProgressOff()
EndFunc

Func _HostnameFromIP(Const $IP)
    Local $sOutput, $aValues, $sReturn
    $sOutput = _Tracert($IP)
    $aValues = StringRegExp($sOutput, '(s*S*s*[)', 3)
    If @error Then Return "UNRESOLVED"
    $sReturn = StringStripWS(StringReplace($aValues[0], "[", ""), 8)
    Return $sReturn
EndFunc

Func _Tracert(Const $sTarget)
    Local $sReturn
    Switch @OSVersion
        Case "WIN_XP", "WIN_XPe", "WIN_2000"
            $sReturn = _RunStdOutRead("tracert -h 1 -w 1 " & $sTarget)
        Case Else
            $sReturn = _RunStdOutRead("tracert -4 -h 1 -w 1 " & $sTarget)
    EndSwitch
    Return $sReturn
EndFunc


Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir)
    Local $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = ''
    While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd
    Return $sOutput
EndFunc   ;==>_RunStdOutRead
Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Thanks for trying it out JScript. I just threw it up here cause it was something I was playing around with and it was pretty solid as a stand-alone app. I'm actually in the process of stripping the GUI and integrating it into a larger application, so I'm probably not going to add the cancel button =P

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I would like to comment about this function

Func _HostnameFromIP(Const $IP)
    Local $sOutput, $aValues, $sReturn
    $sOutput = _Tracert($IP)
    $aValues = StringRegExp($sOutput, '(s*S*s*[)', 3)
    If @error Then Return "UNRESOLVED"
    $sReturn = StringStripWS(StringReplace($aValues[0], "[", ""), 8)
    Return $sReturn
EndFunc

$aValues = StringRegExp($sOutput, '(s*S*s*[)', 3) specifically... I looked at the output from tracert... and it will either return the FQDN or an IP if it can't resolve an FQDN. Either case, the output either the IP or the FQDN should match the RegExp I used. However, it doesn't catch it if it's the IP address. Anyone know why that may be?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

What if DNS is not available?

Br,

UEZ

It returns 'UNRESOLVED' for the FQDN.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I know but what I wanted to say is that this method depends on DNS. Maybe WMI is more accurate but disadvantage is that the system must be online and WMI service up and running properly.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Why not use this SRE? Then you don't need StringReplace or StringStripWS.

'h+(H+)h+['
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@Guinness Nice! I don't necessarily understand the difference between the way the two SREs are made. I would think they would return the same results. I understand that h+ specifies 1 or more vertical white spaces while s* specifies 0 or more of any white space character.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I just tried it with both s+ and s* instead of h+ and kept the grouping the way it was, and it created the same result as using h+. So it was the grouping that did it. So... then... grouping captures while non-grouping does not? I'm confused now =/

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Anything outside of a group doesn't get captured. You can use s if you want.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Anything outside of a group doesn't get captured. You can use s if you want.

OMG! If only I knew that before... thank you for shedding light on that =(

@FireFox I'm not sure what else I could do to speed it up. Tracert is already set to a 1ms timeout and 1 jump. I think the delay is just waiting for Tracert to actually return that it timed out.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

@FireFox I'm not sure what else I could do to speed it up. Tracert is already set to a 1ms timeout and 1 jump. I think the delay is just waiting for Tracert to actually return that it timed out.

Ok. But there is still a difference between a timeout from tracert and a successful.
Link to comment
Share on other sites

You could also try this too >> '((?:h+)H+(?:h+[))'

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You could also try this too >> '((?:h+)H+(?:h+[))'

HAH! I understood it =P. You grouped the whole thing which means "capture everything you put into the SRE", but then you specified (?:h+) which means don't capture this group [which are vertical spaces] then H+ to capture all non-vertical spaces then the same thing on the other end with (?:h+[) except now you're saying to also not capture the bracket.

@FireFox now the problem would lie with what value would I set the timeout? What if the network has a little lag? What if the system takes an extra 1ms to free up a process slot to run the cmd to process the tracert? What if we accidentally timed it out before tracert was even ran and it produces a false negative!?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

now the problem would lie with what value would I set the timeout? What if the network has a little lag? What if the system takes an extra 1ms to free up a process slot to run the cmd to process the tracert? What if we accidentally timed it out before tracert was even ran and it produces a false negative!?

You have to find the right value ;)

If you follow my idea, the user can still re-test without a timeout. You can also put a timeout to the time of the first success +1 sec.

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...