Problem mit _TCPIpToName

  • Hi, Ich schreibe mir gerade ein kleines Ping-Subnet programm (Es scannt einen ip stamm nach rechner die online sind)
    Und habe da ein Problem:
    Ich will mit _TCPIpToName die Namen der Rechner (Nicht nur die IP anzeigen, aber irgendwie gibt _TCPIpToName immer nur "" (Fehler) zurück...

    Ich habe keine ahnung warum...
    Hier ist mein Code:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <INet.au3>
    #Region ### START Koda GUI section ### Form=c:\dokumente und einstellungen\keno\eigene dateien\eigene dokumente\koda\ping subnet.kxf
    $Form1 = GUICreate("Ping Subnet", 423, 450, 192, 124)
    $range = GUICtrlCreateInput("192.168.0.xxx", 0, 0, 121, 21)
    $go = GUICtrlCreateButton("Go", 184, 0, 75, 25, $WS_GROUP)
    $found = GUICtrlCreateEdit("", 0, 40, 273, 409)
    $MaxIp = GUICtrlCreateInput("100", 136, 0, 41, 21)
    $addfield = GUICtrlCreateInput("IP", 288, 40, 121, 21)
    $add = GUICtrlCreateButton("Add zu known IPs", 288, 96, 99, 25, $WS_GROUP)
    $addname = GUICtrlCreateInput("Name", 288, 64, 121, 21)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    $msg = GUIGetMsg ()
    If $msg = -3 Then Exit
    If $msg = $go Then
    GUICtrlSetData ($found, "")
    $max = GUICtrlRead ($maxIp)
    GUICtrlSetData ($go, "Stop")
    GUICtrlSetState ($MaxIp, $GUI_DISABLE)
    GUICtrlSetState ($add, $GUI_DISABLE)
    GUICtrlSetState ($addfield, $GUI_DISABLE)
    GUICtrlSetState ($addname, $GUI_DISABLE)
    GUICtrlSetState ($range, $GUI_DISABLE)
    $split = StringSplit (GUICtrlRead ($range), "xxx")
    $split[2] = $split[1]
    $i = 1
    WinSetTitle ("Ping Subnet", "","Scanning: " & $split[2] & $i)
    Do
    $ping = Ping ($split[2] & $i, 500)
    If $ping <> 0 Then
    $read = GUICtrlRead ($found)
    $name = _TCPIpToName ($split[2] & $i)
    If $name == "" Then
    GUICtrlSetData ($found, $read & IniRead (@ScriptDir & "\names.ini", "names", $split[2] & $i, $split[2] & $i) & " " & $ping & "ms" & @CRLF)
    Else
    GUICtrlSetData ($found, $read & $name & " " & $ping & "ms" & @CRLF)
    EndIf
    EndIf
    $i += 1
    WinSetTitle ("Scanning: " & $split[2] & $i -1, "", "Scanning: " & $split[2] & $i)
    If GUIGetMsg () = $go Then ExitLoop
    Until $i = $max
    GUICtrlSetData ($go, "Go")
    WinSetTitle ("Scanning: " & $split[2] & $i, "", "Ping Subnet")
    GUICtrlSetState ($MaxIp, $GUI_ENABLE)
    GUICtrlSetState ($add, $GUI_ENABLE)
    GUICtrlSetState ($addfield, $GUI_ENABLE)
    GUICtrlSetState ($addname, $GUI_ENABLE)
    GUICtrlSetState ($range, $GUI_ENABLE)
    EndIf
    If $msg = $add Then
    IniWrite (@ScriptDir & "\names.ini", "Names", GUICtrlRead ($addfield), GUICtrlRead ($addname))
    GUICtrlSetData ($addfield, "IP")
    GUICtrlSetData ($addname, "Name")
    EndIf
    WEnd

    [/autoit]

    Thx schonmal :D

    Theorie ist wenn man weiß wie's geht, aber nichts klappt.
    Praxis ist wenn's klappt aber man weiß nicht weiso.

    Bei Microsoft sind Theorie und Praxis vereint: Nichts klappt und keiner weiß wieso ;)

    Einmal editiert, zuletzt von Das Schwert (22. November 2009 um 19:38)

  • Wo denn? Einfach gnz oben?
    Oder auchnoch TcpAccept undso?

    Theorie ist wenn man weiß wie's geht, aber nichts klappt.
    Praxis ist wenn's klappt aber man weiß nicht weiso.

    Bei Microsoft sind Theorie und Praxis vereint: Nichts klappt und keiner weiß wieso ;)

  • Thx, Oscar!!

    Jetzt läufts... (Mit Servernamen...)
    Wer will: Hier ist nochmal der neueste Code...

    (ist aber durch _TCPIPTONAME etwas langsam...)
    Achutng! Es hakt beim anfang des Scans, einfach n moment warten, es gibt sich von allein ;)

    Sonst einfach ; vor TCPStartup (), TCPShutdown () hängen und die If anweisung wieder wegnehmen...


    EDIT:
    Neue version :D
    Mit einer ini für die optionen: TCPipToName lässt sich abschalten (Ohne ist es viel schneller) und der ping timeout lässt sich einstellen.

    Neuer Quelltext:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <INet.au3>
    #Region ### START Koda GUI section ### Form=c:\dokumente und einstellungen\keno\eigene dateien\eigene dokumente\koda\ping subnet.kxf
    $Form1 = GUICreate("Ping Subnet", 423, 450, 192, 124)
    $range = GUICtrlCreateInput("192.168.0.xxx", 0, 0, 121, 21)
    $go = GUICtrlCreateButton("Go", 184, 0, 75, 25, $WS_GROUP)
    $found = GUICtrlCreateEdit("", 0, 40, 273, 409)
    $MaxIp = GUICtrlCreateInput("100", 136, 0, 41, 21)
    $addfield = GUICtrlCreateInput("IP", 288, 40, 121, 21)
    $add = GUICtrlCreateButton("Add zu known IPs", 288, 96, 99, 25, $WS_GROUP)
    $addname = GUICtrlCreateInput("Name", 288, 64, 121, 21)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    If IniRead ("names.ini", "options", "showName", 1) == 1 Then TCPStartup ()
    While 1
    $msg = GUIGetMsg ()
    If $msg = -3 Then Exit
    If $msg = $go Then
    GUICtrlSetData ($found, "")
    $max = GUICtrlRead ($maxIp)
    GUICtrlSetData ($go, "Stop")
    GUICtrlSetState ($MaxIp, $GUI_DISABLE)
    GUICtrlSetState ($add, $GUI_DISABLE)
    GUICtrlSetState ($addfield, $GUI_DISABLE)
    GUICtrlSetState ($addname, $GUI_DISABLE)
    GUICtrlSetState ($range, $GUI_DISABLE)
    $split = StringSplit (GUICtrlRead ($range), "xxx")
    $split[2] = $split[1]
    $i = 1
    WinSetTitle ("Ping Subnet", "","Scanning: " & $split[2] & $i)
    ;Optionen werden hier ausgelesen
    $timeout = IniRead ("names.ini", "options", "timeout", 500)
    $tcpname = IniRead ("names.ini", "options", "showName", 1)
    Do
    $ping = Ping ($split[2] & $i, $timeout)
    If $ping <> 0 Then
    $read = GUICtrlRead ($found)
    If $tcpname = 1 Then
    $name = _TCPIpToName ($split[2] & $i)
    If $name == "" Then
    GUICtrlSetData ($found, $read & IniRead (@ScriptDir & "\names.ini", "names", $split[2] & $i, $split[2] & $i) & " " & $ping & "ms" & @CRLF)
    Else
    GUICtrlSetData ($found, $read & $name & " " & $split[2] & $i & " " & $ping & "ms" & @CRLF)
    EndIf
    ElseIf $tcpname <> 1 Then
    GUICtrlSetData ($found, $read & IniRead (@ScriptDir & "\names.ini", "names", $split[2] & $i, $split[2] & $i) & " " & $ping & "ms" & @CRLF)
    EndIf
    EndIf
    $i += 1
    WinSetTitle ("Scanning: " & $split[2] & $i -1, "", "Scanning: " & $split[2] & $i)
    If GUIGetMsg () = $go Then ExitLoop
    Until $i = $max
    GUICtrlSetData ($go, "Go")
    WinSetTitle ("Scanning: " & $split[2] & $i, "", "Ping Subnet")
    GUICtrlSetState ($MaxIp, $GUI_ENABLE)
    GUICtrlSetState ($add, $GUI_ENABLE)
    GUICtrlSetState ($addfield, $GUI_ENABLE)
    GUICtrlSetState ($addname, $GUI_ENABLE)
    GUICtrlSetState ($range, $GUI_ENABLE)
    EndIf
    If $msg = $add Then
    IniWrite (@ScriptDir & "\names.ini", "Names", GUICtrlRead ($addfield), GUICtrlRead ($addname))
    GUICtrlSetData ($addfield, "IP")
    GUICtrlSetData ($addname, "Name")
    EndIf
    WEnd
    Func OnAutoItExit ()
    If IniRead ("names.ini", "options", "showName", 1) == 1 Then TCPShutdown ()
    EndFunc

    [/autoit]

    Names.ini (Datei mit den Optionen und für mit Namen gespeicherte IP adressen:

    Spoiler anzeigen

    [Names]
    192.168.0.1=Router
    [options]
    timeout=300
    showName=1

    Einfach showName auf 0 setzen um Namens anzeige zu deaktivieren...

    Theorie ist wenn man weiß wie's geht, aber nichts klappt.
    Praxis ist wenn's klappt aber man weiß nicht weiso.

    Bei Microsoft sind Theorie und Praxis vereint: Nichts klappt und keiner weiß wieso ;)

    Einmal editiert, zuletzt von Das Schwert (30. August 2009 um 19:52)