Jump to content

Find Proxmox web interface ( or any local site really )


argumentum
 Share

Recommended Posts

I needed to ping Proxmox but it didn't so, let's "ping" the web interface ( or any TCP IPv4 in sight really ).
If it connects, there is something there.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <GuiIPAddress.au3>

Local $iW = 400, $iH = 200
Global $hGui = GUICreate(Chr(160) & "Find web interface", $iW, $iH)
Global $idInput = _GUICtrlIpAddress_Create($hGui, nextLeft(5), 5, nextLeft(120), 21, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlIpAddress_Set($idInput, GetDefaultRange())
Global $idPort = GUICtrlCreateInput("8006", nextLeft(), 5, nextLeft(100), 21, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
Global $idBttn = GUICtrlCreateButton("Run", nextLeft(), 5, nextLeft(125), 21)
Global $idEdit = GUICtrlCreateEdit("The default port is 8006 because" & @CRLF & 'am looking for the running Proxmox.', 5, 30, $iW - 10, $iH - 30)
GUICtrlSetData($idEdit, @CRLF & @CRLF & "Can take comma delimited (8006,443)" & @CRLF & "Use at will.", 1)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            GUIDelete()
            Exit
        Case $idBttn
            idCtrlsSetState($GUI_DISABLE)
            GUICtrlSetData($idEdit, "")
            findSite()
            idCtrlsSetState($GUI_ENABLE)
    EndSwitch
WEnd

Func findSite()
    Local $aETTF ; "Estimated Time To Finish" data holder
    _EstimatedTime($aETTF) ; called with just the data holder to init. it
    Local $sHint, $vData, $n, $iSocket, $octets = _GUICtrlIpAddress_Get($idInput)
    Local $aPorts = StringSplit(StringReplace(GUICtrlRead($idPort), '(', ''), ',')
    For $m = 1 To $aPorts[0]
        $aPorts[$m] = Int($aPorts[$m])
        If $aPorts[$m] < 1 Or $aPorts[$m] > 65535 Then Return GUICtrlSetData($idEdit, '..port(s) should be that of a web site')
    Next
    Local $aOct = StringSplit($octets, ".")
    If UBound($aOct) <> 5 Then Return GUICtrlSetData($idEdit, '..IPv4 should be X.X.X.')
    $octets = $aOct[1] & '.' & $aOct[2] & '.' & $aOct[3] & '.'
    TCPStartup()
    Opt("TCPTimeout", 100)
    For $n = 1 To 254
        _EstimatedTime($aETTF, $n, 255)
        If GUIGetMsg() = -3 Then ExitLoop
        GUICtrlSetData($idBttn, $aETTF[1] & "  -  " & $aETTF[4] & " %")
        For $m = 1 To $aPorts[0]
            If Int($aPorts[$m]) < 1 Or $aPorts[$m] > 65535 Then ContinueLoop
            $iSocket = TCPConnect($octets & $n, $aPorts[$m])
            If @error Then ContinueLoop
            $vData = Binary("")
            Sleep(10)
            $vData = TCPRecv($iSocket, 4096, 1)
            TCPCloseSocket($iSocket)
            If BinaryLen($vData) Then
                $sHint = Get22hint($vData)
            Else
                $sHint = GetHint($octets & $n, $aPorts[$m])
            EndIf
            GUICtrlSetData($idEdit, $octets & $n & ':' & $aPorts[$m] & (StringLen($sHint) ? ' ' & @TAB & '[ ' & $sHint & ' ]' : '') & @CRLF, 1)
        Next
    Next
    TCPShutdown()
    GUICtrlSetData($idBttn, "...")
    While GUIGetMsg()
    WEnd
    GUICtrlSetData($idEdit, ($n = 255 ? "Done" : "Canceled") & '  ( ' & $aETTF[0] & ' )' & @CRLF, 1)
    GUICtrlSetData($idBttn, "Run")
EndFunc   ;==>findSite

Func Get22hint($vData)
    Local $a1 = StringSplit(BinaryToString($vData), Chr(0)) ; filter nul
    Local $a2 = StringSplit(BinaryToString($a1[1]), @CRLF) ; get 1st line/only line
    Return $a2[1]
EndFunc   ;==>Get22hint

Func GetHint($IPv4, $iPort)
    Local $sHttp = ($iPort = 80 ? "http" : "https")
    Local $iPID = Run(@ComSpec & ' /C curl -k -v -L ' & $sHttp & '://"' & $IPv4 & ':' & $iPort, @ScriptDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
    ProcessWaitClose($iPID)
    Local $sHint = "", $sTxt = StdoutRead($iPID) & StderrRead($iPID)
    If StringInStr($sTxt, '<title>') Then
        $sHint = StringMid($sTxt, StringInStr($sTxt, '<title>') + 7, StringInStr($sTxt, '</title>') - StringInStr($sTxt, '<title>') - 7)
        Return $sHint
    EndIf ; to dig deep use something like NMAP ( https://nmap.org/ ). This is just a simple tool.
    If StringInStr($sTxt, 'TrueNAS') Then Return 'TrueNAS'
    If StringInStr($sTxt, "Issue another request to this URL: 'https://" & $IPv4 & "/ui/'") Then Return 'TrueNAS'
    If StringInStr($sTxt, 'HTTP/1.1 403 Forbidden') Then Return 'HTTP/1.1 403 Forbidden'
    If StringInStr($sTxt, '< Server: ') Then
        Local $a1 = StringSplit($sTxt, '< Server: ', 1)
        Local $a2 = StringSplit($a1[2], @CRLF, 0)
        Return 'Server: ' & $a2[1]
    EndIf
    Return ""
EndFunc   ;==>GetHint

Func nextLeft($i = 0)
    Local Static $iLeft = 0
    $iLeft += $i
    Return ($i ? $i : $iLeft)
EndFunc   ;==>nextLeft

Func idCtrlsSetState($iState)
    GUICtrlSetState($idBttn, $iState)
    _GUICtrlIpAddress_ShowHide($idInput, ($iState = $GUI_DISABLE ? @SW_HIDE : @SW_SHOW))
    GUICtrlSetState($idPort, ($iState = $GUI_DISABLE ? $GUI_HIDE : $GUI_SHOW))
    GUICtrlSetState($idEdit, $iState)
EndFunc   ;==>idCtrlsSetState

Func GetDefaultRange()
    Local $sTxt = GetDefaultGateway()
    Return StringLeft($sTxt, StringInStr($sTxt, '.', 0, 3)) & 'X'
EndFunc   ;==>GetDefaultRange

Func GetDefaultGateway() ; https://www.autoitscript.com/forum/topic/193342-how-to-change-default-gateway-and-preferred-dns-server/?do=findComment&comment=1387443
    Local $out = "", $PID = Run(@ComSpec & " /c route print", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
    While 1
        $out &= StdoutRead($PID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($out, "\s*0.0.0.0\s+0.0.0.0\s+(\d+\.\d+\.\d+\.\d+).*", 1)[0]
EndFunc   ;==>GetDefaultGateway

;===============================================================================
;
; Function Name:    _EstimatedTime() ; https://www.autoitscript.com/forum/topic/177371-_estimatedtime-calculate-estimated-time-of-completion/
; Description:      calculate estimated time of completion
; Parameter(s):     $a  - holds the data
;                   $iCurrentCount  - Current count
;                   $iTotalCount - Total count
; Requirement(s):   #include <Date.au3>
; Return Value(s):  false on incomplete data for assessment
; Author(s):        argumentum
; Note(s):          read the comments
;
;===============================================================================
Func _EstimatedTime(ByRef $a, $iCurrentCount = "", $iTotalCount = "")
    If $iCurrentCount & $iTotalCount = "" Then ; initialize
        $a = ""
        Dim $a[12]
        $a[5] = TimerInit() ; handle for TimerDiff()
        $a[0] = "00:00:00"
        $a[1] = "00:00:00"
        $a[2] = _NowCalc() ; starting date and time
        $a[3] = ""
        $a[4] = "0"
    Else
        If $iTotalCount = 0 Then Return False
        If $iCurrentCount > $iTotalCount Then $iCurrentCount = $iTotalCount
        _TicksToTime(Int(TimerDiff($a[5])), $a[6], $a[7], $a[8])
        _TicksToTime(Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount - $iCurrentCount)), $a[9], $a[10], $a[11])
        $a[0] = StringFormat("%02i:%02i:%02i", $a[6], $a[7], $a[8]) ; elapsed time
        $a[1] = StringFormat("%02i:%02i:%02i", $a[9], $a[10], $a[11]) ; estimated total time
        $a[3] = _DateAdd("s", Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount) / 1000), $a[2]) ; estimated date and time of completion
        $a[4] = Int($iCurrentCount / $iTotalCount * 100) ; percentage done
    EndIf
    Return True
EndFunc   ;==>_EstimatedTime

Not much of an example but I scanned my network in under 30 secs. Nice toy to have :)

Edit: added a hint of what may be at that IPv4 and comma delimited ports can be used.

Edit2:  Version with IP and mask:

image.png.37f4dcb68f0c341d30f963bcc9fabd86.png

Spoiler
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <GuiIPAddress.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>

Global $g_Route, $g_Netmask, $g_aWM_NOTIFY[2] = [0]
GetDefaultsIPv4($g_Route, $g_Netmask) ; get your PC's 1st current
Global $g_aIPRange = GetRange($g_Route, $g_Netmask)
Opt("GUIDataSeparatorChar", Chr(1)) ;"|" is the default
Local $iW = 440, $iH = 350, $iL1 = nextLeft(5), $iL2 = nextLeft(120)
Global $hGui = GUICreate(Chr(160) & "Find WebUI", $iW, $iH)
Global $idCurrentIp = GUICtrlCreateInput("", $iL1, 5, $iL2, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUICtrlSetState($idCurrentIp, $GUI_DISABLE)
GUICtrlSetState($idCurrentIp, $GUI_HIDE)
Global $idInput = _GUICtrlIpAddress_Create($hGui, $iL1, 5, $iL2, 21, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlIpAddress_Set($idInput, $g_Route)
Global $idMask = _GUICtrlIpAddress_Create($hGui, nextLeft(), 5, nextLeft(120), 21, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlIpAddress_Set($idMask, $g_Netmask)
Global $idPort = GUICtrlCreateInput("8006", nextLeft(), 5, nextLeft(60), 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
Global $idBttn = GUICtrlCreateButton("Run", nextLeft(), 5, nextLeft(125), 21)
Global $idEdit = GUICtrlCreateEdit("The default port is 8006 because" & ' am looking for the running Proxmox.', 5, 30, $iW - 10, 130, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUICtrlSetData($idEdit, @CRLF & @CRLF & "Can take comma delimited (8006,443,80,22)" & @CRLF & "Double-click entries to browse them. ( will paste to clipboard too )", 1)
GUICtrlSetData($idEdit, @CRLF & @CRLF & "Close while running to cancel. When not running, closing will exit." & @CRLF, 1)
Global $idLv = GUICtrlCreateListView("IPv4 : port" & Chr(1) & "Hint", 5, 165, $iW - 10, $iH - 170)
_GUICtrlListView_SetColumnWidth($idLv, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($idLv, 1, $LVSCW_AUTOSIZE_USEHEADER)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case -3
            GUIDelete()
            Exit
        Case $idBttn
            idCtrlsSetState($GUI_DISABLE)
            $g_Route = _GUICtrlIpAddress_Get($idInput)
            $g_Netmask = _GUICtrlIpAddress_Get($idMask)
            $g_aIPRange = GetRange($g_Route, $g_Netmask)
            _GUICtrlEdit_AppendText($idEdit, @CRLF & "..scanning " & $g_aIPRange[0] & " IPs.  (" & $g_Route & ' - ' & $g_Netmask & ')' & @CRLF)
            findSite($g_aIPRange)
            idCtrlsSetState($GUI_ENABLE)
    EndSwitch
WEnd

Func findSite($aIPRange)
    Local $iFound, $aETTF ; "Estimated Time To Finish" data holder
    _EstimatedTime($aETTF) ; called with just the data holder to init. it
    Local $sHint, $vData, $n, $iSocket ; , $octets = _GUICtrlIpAddress_Get($idInput)
    Local $sPorts = "", $aPorts = StringSplit(StringReplace(GUICtrlRead($idPort), '(', ''), ',')
    For $m = 1 To $aPorts[0]
        $aPorts[$m] = Int($aPorts[$m])
        If $aPorts[$m] < 1 Or $aPorts[$m] > 65535 Then Return _GUICtrlEdit_AppendText($idEdit, '..port(s) should be that of a web site')
        $sPorts &= ',' & $aPorts[$m]
    Next
    $sPorts = StringTrimLeft($sPorts, 1)
    _GUICtrlEdit_AppendText($idEdit, 'Searching in port' & (StringInStr($sPorts, ",") ? 's' : '') & ' ' & $sPorts & @CRLF)
    TCPStartup()
    Opt("TCPTimeout", 100)
    For $n = 1 To $aIPRange[0]
        _EstimatedTime($aETTF, $n, $aIPRange[0])
        GUICtrlSetData($idBttn, $aETTF[1] & "  -  " & $aETTF[4] & " %")
        GUICtrlSetData($idCurrentIp, $aIPRange[$n])
        For $m = 1 To $aPorts[0]
            If GUIGetMsg() = -3 Then ExitLoop 2
            If Int($aPorts[$m]) < 1 Or $aPorts[$m] > 65535 Then ContinueLoop
            $iSocket = TCPConnect($aIPRange[$n], $aPorts[$m])
            If @error Then ContinueLoop
            $vData = Binary("")
            Sleep(10)
            $vData = TCPRecv($iSocket, 4096, 1)
            TCPCloseSocket($iSocket)
            If BinaryLen($vData) Then
                $sHint = Get22hint($vData)
            Else
                $sHint = GetHint($aIPRange[$n], $aPorts[$m])
            EndIf
            $iFound = _GUICtrlListView_FindText($idLv, $aIPRange[$n] & ':' & $aPorts[$m])
            If $iFound = -1 Then
                GUICtrlCreateListViewItem($aIPRange[$n] & ':' & $aPorts[$m] & Chr(1) & (StringLen($sHint) ? $sHint : ''), $idLv)
                _GUICtrlListView_SetColumnWidth($idLv, 0, $LVSCW_AUTOSIZE_USEHEADER)
                _GUICtrlListView_SetColumnWidth($idLv, 1, $LVSCW_AUTOSIZE_USEHEADER)
            Else
                _GUICtrlListView_SetItemSelected($idLv, $iFound)
            EndIf
        Next
    Next
    TCPShutdown()
    _GUICtrlEdit_AppendText($idEdit, ($n > $aIPRange[0] ? "Done" : "Canceled") & '  ( ' & $aETTF[0] & ' )' & @CRLF)
    GUICtrlSetData($idBttn, "Run")
    Sleep(400)
    While GUIGetMsg()
    WEnd
EndFunc   ;==>findSite

Func Get22hint($vData) ; is it SSH ?
    Local $a1 = StringSplit(BinaryToString($vData), Chr(0)) ; filter nul
    Local $a2 = StringSplit(BinaryToString($a1[1]), @CRLF) ; get 1st line/only line
    Return $a2[1]
EndFunc   ;==>Get22hint

Func GetHint($IPv4, $iPort)
    Local $sHttp = ($iPort = 22 ? 'ssh' : ($iPort = 80 ? "http" : "https"))
    Local $iPID = Run(@ComSpec & ' /C curl -k -v -L ' & $sHttp & '://"' & $IPv4 & ':' & $iPort, @ScriptDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
    ProcessWaitClose($iPID)
    Local $sHint = "", $sTxt = StdoutRead($iPID) & StderrRead($iPID)
    If StringInStr($sTxt, '<title>') Then
        $sHint = StringMid($sTxt, StringInStr($sTxt, '<title>') + 7, StringInStr($sTxt, '</title>') - StringInStr($sTxt, '<title>') - 7)
        Return $sHint
    EndIf ; to dig deep use something like NMAP ( https://nmap.org/ ). This is just a simple tool.
    If StringInStr($sTxt, 'TrueNAS') Then Return 'TrueNAS'
    If StringInStr($sTxt, "Issue another request to this URL: 'https://" & $IPv4 & "/ui/'") Then Return 'TrueNAS'
    If StringInStr($sTxt, 'HTTP/1.1 403 Forbidden') Then Return 'HTTP/1.1 403 Forbidden'
    If StringInStr($sTxt, '< Server: ') Then
        Local $a1 = StringSplit($sTxt, '< Server: ', 1)
        Local $a2 = StringSplit($a1[2], @CRLF, 0)
        Return 'Server: ' & $a2[1]
    EndIf
    Return ""
EndFunc   ;==>GetHint

Func nextLeft($i = 0)
    Local Static $iLeft = 0
    $iLeft += $i
    Return ($i ? $i : $iLeft)
EndFunc   ;==>nextLeft

Func idCtrlsSetState($iState)
    GUICtrlSetState($idBttn, $iState)
    GUICtrlSetState($idCurrentIp, ($iState = $GUI_DISABLE ? $GUI_SHOW : $GUI_HIDE))
    _GUICtrlIpAddress_ShowHide($idInput, ($iState = $GUI_DISABLE ? @SW_HIDE : @SW_SHOW))
    _GUICtrlIpAddress_ShowHide($idMask, ($iState = $GUI_DISABLE ? @SW_HIDE : @SW_SHOW))
    GUICtrlSetState($idPort, ($iState = $GUI_DISABLE ? $GUI_HIDE : $GUI_SHOW))
    GUICtrlSetState($idEdit, $iState)
EndFunc   ;==>idCtrlsSetState

;===============================================================================
;
; Function Name:    _EstimatedTime() ; https://www.autoitscript.com/forum/topic/177371-_estimatedtime-calculate-estimated-time-of-completion/
; Description:      calculate estimated time of completion
; Parameter(s):     $a  - holds the data
;                   $iCurrentCount  - Current count
;                   $iTotalCount - Total count
; Requirement(s):   #include <Date.au3>
; Return Value(s):  false on incomplete data for assessment
; Author(s):        argumentum
; Note(s):          read the comments
;
;===============================================================================
Func _EstimatedTime(ByRef $a, $iCurrentCount = "", $iTotalCount = "")
    If $iCurrentCount & $iTotalCount = "" Then ; initialize
        $a = ""
        Dim $a[12]
        $a[5] = TimerInit() ; handle for TimerDiff()
        $a[0] = "00:00:00"
        $a[1] = "00:00:00"
        $a[2] = _NowCalc() ; starting date and time
        $a[3] = ""
        $a[4] = "0"
    Else
        If $iTotalCount = 0 Then Return False
        If $iCurrentCount > $iTotalCount Then $iCurrentCount = $iTotalCount
        _TicksToTime(Int(TimerDiff($a[5])), $a[6], $a[7], $a[8])
        _TicksToTime(Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount - $iCurrentCount)), $a[9], $a[10], $a[11])
        $a[0] = StringFormat("%02i:%02i:%02i", $a[6], $a[7], $a[8]) ; elapsed time
        $a[1] = StringFormat("%02i:%02i:%02i", $a[9], $a[10], $a[11]) ; estimated total time
        $a[3] = _DateAdd("s", Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount) / 1000), $a[2]) ; estimated date and time of completion
        $a[4] = Int($iCurrentCount / $iTotalCount * 100) ; percentage done
    EndIf
    Return True
EndFunc   ;==>_EstimatedTime

Func GetRange($sIP, $sNetMask)
    Local $iCount = 0, $aIPRange[1001] = [$iCount], $iIP, $iMask
    $aIP = StringSplit($sIP, ".", 2)
    $aMask = StringSplit($sNetMask, ".", 2)

    For $i = 0 To 3
        $iIP = BitShift($iIP, -8)
        $iMask = BitShift($iMask, -8)
        $iIP += $aIP[$i]
        $iMask += $aMask[$i]
    Next

    Local $iNet = BitAND($iIP, $iMask)
    Local $iFirst = $iNet + 1
    Local $iBCast = BitOR($iNet, BitNOT($iMask))
    Local $iLast = $iBCast - 1

    Local $sIP2, $iIP
    For $i = $iFirst To $iLast
        $iIP = $i
        $sIP2 = ""
        For $j = 1 To 4
            $sIP2 = BitAND($iIP, 0xFF) & "." & $sIP2
            $iIP = BitShift($iIP, 8)
        Next
        If $iCount + 2 > UBound($aIPRange) Then ReDim $aIPRange[$iCount + 1001]
        $iCount += 1
        $aIPRange[$iCount] = StringTrimRight($sIP2, 1)
        If $iCount > 65536 Then
            _GUICtrlEdit_AppendText($idEdit, '..way too many IPs. Acting on first 65537.' & @CRLF)
            ExitLoop ; 24-bit block: 16,777,216 ; 20-bit block: 1,048,576 ; 16-bit block: 65,536 ( takes 2 hours )
        EndIf ; ...if your scan is too large, you may benefit from a script designed for that.
    Next
    ReDim $aIPRange[$iCount + 1]
    $aIPRange[0] = $iCount
    Return $aIPRange
EndFunc   ;==>GetRange

Func GetDefaultsIPv4(ByRef $_Route, ByRef $_Netmask)
    Local $out = "", $PID = Run(@ComSpec & " /c route print", @ScriptDir, @SW_HIDE, 6)
    While 1
        Sleep(10)
        $out &= StdoutRead($PID)
        If @error Then ExitLoop
    WEnd
    Local $_Gateway = "", $_Interface = ""
    $_Netmask = ""
    $_Route = ""
    Local $n, $aTemp, $aOut = StringSplit($out, @CRLF, 1)
    For $n = 1 To $aOut[0]
        $aTemp = StringSplit(StringStripWS($aOut[$n], 7), " ")
        If UBound($aTemp) <> 6 Then ContinueLoop
        If StringInStr($aTemp[3], ".", 0, 3) Then
            $_Gateway = $aTemp[3]
            $_Interface = $aTemp[4]
            $_Route = StringLeft($aTemp[3], StringInStr($aTemp[3], '.', 0, 3)) & '0'
            ExitLoop
        EndIf
    Next
    For $n = 1 To $aOut[0]
        $aTemp = StringSplit(StringStripWS($aOut[$n], 7), " ")
        If UBound($aTemp) <> 6 Then ContinueLoop
        If $aTemp[1] = $_Route Then
            $_Netmask = $aTemp[2]
            ExitLoop
        EndIf
    Next
EndFunc   ;==>GetDefaultsIPv4

Func Adlib_WM_NOTIFY()
    AdlibUnRegister(Adlib_WM_NOTIFY)
    If $g_aWM_NOTIFY[1] < 0 Then Return
    Switch $g_aWM_NOTIFY[0]
        Case $NM_DBLCLK
            Local $sIpPort = _GUICtrlListView_GetItemText($idLv, $g_aWM_NOTIFY[1], 0), $iPort = Int(StringTrimLeft($sIpPort, StringInStr($sIpPort, ":")))
            ClipPut($sIpPort)
            ShellExecute(($iPort = 22 ? 'ssh' : ($iPort = 80 ? "http" : "https")) & '://' & $sIpPort)
    EndSwitch
    $g_aWM_NOTIFY[0] = 0
EndFunc   ;==>Adlib_WM_NOTIFY

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $idLv
    If Not IsHWnd($idLv) Then $hWndListView = GUICtrlGetHandle($idLv)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $g_aWM_NOTIFY[0] = $iCode
                    $g_aWM_NOTIFY[1] = DllStructGetData($tInfo, "Index")
                    If $g_aWM_NOTIFY[1] > -1 Then AdlibRegister(Adlib_WM_NOTIFY, 100)
                    ; No return value
;~              Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
;~                  $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~                  ;Return 1 ; not to allow the default processing
;~                  Return 0 ; allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

for those that may need it. ( or just @MattyD :D )

Edit3: Compiled it and placed it in the download area.
..and I should have put the data in a listview with a click-click to open the finding but, how many times will one not find their computers :lol:

Edit4: Added the listview to double-click and go to the ip:port.

Edited by argumentum
newer version

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 2 weeks later...

Nice, I was more thinking along the lines of something like this though - it'll allow you scan to scan an entire subnet if you're not using a /24.

GetRange("10.0.0.78", "255.255.240.0")

Func GetRange($sIP, $sNetMask)
    Local $aIPRange[2][4], $iIP, $iMask
    $aIP = StringSplit($sIP, ".", 2)
    $aMask = StringSplit($sNetMask, ".", 2)

    For $i = 0 To 3
        $iIP = BitShift($iIP, -8)
        $iMask = BitShift($iMask, -8)
        $iIP += $aIP[$i]
        $iMask += $aMask[$i]
    Next

    Local $iNet =  BitAND($iIP, $iMask)
    Local $iFirst = $iNet + 1
    Local $iBCast = BitOr($iNet, BitNot($iMask))
    Local $iLast = $iBCast - 1

    Local $sIP2, $iIP
    For $i = $iFirst To $iLast
        $iIP = $i
        $sIP2 = ""
        For $j = 1 To 4
            $sIP2 = BitAND($iIP, 0xFF) & "." & $sIP2
            $iIP = BitShift($iIP, 8)
        Next
        ConsoleWrite(StringTrimRight($sIP2, 1) & @CRLF)
    Next
EndFunc

you'd then just nest the for loops...   On second thought, its probably better to calculate the dotted notation on the fly. - Updated example!
 

Edited by MattyD
Link to comment
Share on other sites

>GetRange("10.0.0.78", "255.255.240.0")
GetDefaultGateway() gets the IP but I'll need a get-default-mask() and I don't know a simple ( copy'n'paste ) way to do it. Can you give me that ?
Else, I'll do it searching line by line ( ugly looking ) 🤔

Edit: done.

6 hours ago, MattyD said:

its probably better to calculate the dotted notation on the fly

on that regard, I'll build an array so the estimated-time() has a min/max to calculate that :)

Edited by argumentum
done

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

On 9/10/2024 at 7:19 PM, argumentum said:

for those that may need it. ( or just @MattyD :D )

hehe - looking good. Pulling that default mask is a nice touch.

It's obviously not an issue, but to be hyper nit-picky there's no real need to keep expanding that array.  ($iLast - $iFirst) + 1 will get you a count :)

Also putting that limit on IP addresses was probably a good idea too. God help anyone who actually has need of a /16 subnet!!

Link to comment
Share on other sites

Hey mate, just a correction from my side -

I've found our IP integer rolls over to a "double" in some scenarios, which invalidates the bit-wise operations later in the function. So it looks like we'll need to force the values to be 32 bit at line 189

Never mind, I can't reproduce the issue - so I've probably done something dumb. (I thought I was pulling an incorrect range).

Edit 2: Ok so we're getting the double type because we're incrementing with a string. Essentially we're doing things like $iNetMask += "255".  The the bitwise funcs do look to be  converting back to 32bit for their operations though.

Just as a float  255.255.255.0 (0xFFFFFF00) was showing up as (0xC070000000000000).  I had assumed BitAnd etc was complaining about that!

Edited by MattyD
Link to comment
Share on other sites

1 hour ago, MattyD said:

...so I've probably done something dumb...

Well, is your code !  :P

Yes, ...when releasing code for general consumption, the code should have stupid checking error checking because the user may enter something outside the scope of the code's evaluation. Say : mask = 256.256.256.0 or some other non-sense that in a moment of ... oops ?, may/will crash the script.

If you find that something should be better post the code or let me know. :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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