Ping abbrechen

  • hallo liebe community

    als sys-admin, brauche ich ab und zu einen ip scanner, der mir mitteilt welche ip's erreichbar sind.
    ich hab da mal was programmiert, habe allerdings keine ahnung, wie ich den ping-prozess abbrechen soll.

    kann mir jemand dabei helfen?

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <iNet.au3>
    #include <GuiIPAddress.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <GuiStatusBar.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ListViewConstants.au3>
    #Include <GuiListView.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.6.0
    Author: Gianni

    [/autoit] [autoit][/autoit] [autoit]

    Script Function:
    Pingt IP's im LAN

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; Script Start - Add your code below here

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=d:\programmierung\autoit\pingmylan\form\form.kxf
    $form = GUICreate("pingMyLAN", 267, 273, 192, 124)
    $inpIP = _GUICtrlIpAddress_Create($form, 96, 16, 100, 21)
    _GUICtrlIpAddress_Set($inpIP, "192.168.0.1")
    $labelIP = GUICtrlCreateLabel("IP-Adresse:", 16, 16, 75, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    $labelBis = GUICtrlCreateLabel("-", 202, 8, 12, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial")
    $inpBis = GUICtrlCreateInput("255", 216, 16, 33, 21)
    $statusBar = _GUICtrlStatusBar_Create($form)
    _GUICtrlStatusBar_SetText ($statusBar, "Stop")
    $ListView1 = GUICtrlCreateListView("IP | Hostname", 8, 88, 250, 150)
    _GUICtrlListView_SetColumnWidth ($ListView1, 0, 100)
    _GUICtrlListView_SetColumnWidth ($ListView1, 1, 135)
    $btnStart = GUICtrlCreateButton("Start", 120, 48, 59, 25, $WS_GROUP)
    $btnStop = GUICtrlCreateButton("Stop", 192, 48, 59, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $btnStart
    $pingIP = _GUICtrlIpAddress_Get($inpIP)
    $pingBis = GUICtrlRead($inpBis)
    _pingIP($pingIP, $pingBis)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _pingIP($ip, $ipBis)
    $splitIP = StringSplit($ip, ".")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = $splitIP[4] To $ipBis
    $ip = String($splitIP[1] & "." & $splitIP[2] & "." & $splitIP[3] & "." & $i)
    _GUICtrlStatusBar_SetText ($statusBar, "Ping: " & $ip)
    $ping = Ping($ip, 1000)

    [/autoit] [autoit][/autoit] [autoit]

    If $ping > 0 Then
    $host = _TCPIpToName($ip)
    $item1 = GUICtrlCreateListViewItem($ip & "|" & $host, $ListView1)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    ps: ich weiss, es wurde schon so etwas programmiert, allerdings möchte ich mein eigenes gebrauchen und noch für weitere interne sachen erweitern.

    vielen dank für die hilfe

    Einmal editiert, zuletzt von Gianni (15. Oktober 2010 um 16:27)

  • Du könntest den Ping über Cmd ausführen, da kannst du das Fenster dann einfach schließen wenns abgebrochen werden soll...
    Mit

    [autoit]

    StdoutRead

    [/autoit]

    dann das da auslesen um die Antwort zu erhalten:

    [autoit]


    #include <Process.au3>
    _RunDOS("ping 127.0.0.1")

    [/autoit]


    Schließen dann mit

    [autoit]


    ProcessClose

    [/autoit]
  • Hi,

    ich würde zuerst den GUI Event Modus von "MessageLoop" zu "OnEvent" ändern.
    Das würde vieles vereinfachen ;)

    Ich hab mal dein Script dementsprechend umgebaut:

    Spoiler anzeigen
    [autoit]


    #include <iNet.au3>
    #include <GuiIPAddress.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <GuiStatusBar.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ListViewConstants.au3>
    #Include <GuiListView.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.6.0
    Author: Gianni

    [/autoit] [autoit][/autoit] [autoit]

    Script Function:
    Pingt IP's im LAN

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; Script Start - Add your code below here

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=d:\programmierung\autoit\pingmylan\form\form.kxf
    Global $ipSearchStarted = 0
    Global $pingIP = "0.0.0.0"
    Global $pingBis = 0

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    $form = GUICreate("pingMyLAN", 267, 273, 192, 124)
    $inpIP = _GUICtrlIpAddress_Create($form, 96, 16, 100, 21)
    _GUICtrlIpAddress_Set($inpIP, "192.168.0.1")
    $labelIP = GUICtrlCreateLabel("IP-Adresse:", 16, 16, 75, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    $labelBis = GUICtrlCreateLabel("-", 202, 8, 12, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial")
    $inpBis = GUICtrlCreateInput("255", 216, 16, 33, 21)
    $statusBar = _GUICtrlStatusBar_Create($form)
    _GUICtrlStatusBar_SetText ($statusBar, "Stop")
    $ListView1 = GUICtrlCreateListView("IP | Hostname", 8, 88, 250, 150)
    _GUICtrlListView_SetColumnWidth ($ListView1, 0, 100)
    _GUICtrlListView_SetColumnWidth ($ListView1, 1, 135)
    $btnStart = GUICtrlCreateButton("Start", 120, 48, 59, 25, $WS_GROUP)
    $btnStop = GUICtrlCreateButton("Stop", 192, 48, 59, 25, $WS_GROUP)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    GUICtrlSetOnEvent($btnStart, "StartButton")
    GUICtrlSetOnEvent($btnStop, "StopButton")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    Func StartButton()
    If $ipSearchStarted Then return 0
    $IPSearchStarted = 1
    $pingIP = _GUICtrlIpAddress_Get($inpIP)
    $pingBis = GUICtrlRead($inpBis)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func StopButton()
    If NOT $ipSearchStarted Then return 0
    $IPSearchStarted = 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func CLOSEClicked()
    If $ipSearchStarted Then
    $a = MsgBox(1, "Ping Suche noch aktiv!", "Soll die Ping Suche abgebrochen werden?")
    If NOT ($a = 1) Then Return
    EndIf
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _pingIP($ip, $ipBis)
    $splitIP = StringSplit($ip, ".")
    For $i = $splitIP[4] To $ipBis
    If Not $ipSearchStarted Then ExitLoop
    $ip = String($splitIP[1] & "." & $splitIP[2] & "." & $splitIP[3] & "." & $i)
    _GUICtrlStatusBar_SetText ($statusBar, "Ping: " & $ip)
    $ping = Ping($ip, 250)
    If $ping > 0 Then
    $host = _TCPIpToName($ip)
    $item1 = GUICtrlCreateListViewItem($ip & "|" & $host, $ListView1)
    EndIf
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(1000)
    If $ipSearchStarted Then
    _pingIP($pingIP, $pingBis)
    $ipSearchStarted = 0
    _GUICtrlStatusBar_SetText ($statusBar, "Stop")
    EndIf
    WEnd

    [/autoit]

    Enjoy...

    Gruß
    CD

    [Edit]
    gespoilt...