Swich -> Case

  • Hallo zusammen,


    ich habe mal wieder ein kleines Problem. Das nachfolgende Skript ließt die IPAdresse des jeweiligen Clientsystems und gibt diese in einem IP Adressenfeld aus. Gleichzeitig soll anhand der IP Adresse ermittelt werden in welchem Netz das System sich befindet. Aktuell habe ich es mit "Switch/Case" realisiert. Meine Frage ist nun ob es möglich wäre die einzelenen IP-Adressbereiche (192.168.1, 192.168.2 usw.) und die jeweilige Zuordnung (Netz 1, Netz 2 usw.) aus einer vorgefertigten Datei (z.B. .INI) auszulesen und mit der momentanen IPAdresse zu vergleichen und zuzuordnen.


    Inhalt einer Beispiel.ini:

    [Netz 1]

    192.168.1

    [Netz 2]

    192.168.2


    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiIPAddress.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt('MustDeclareVars', 1)
    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("Form1", 314, 179, 192, 114)
    Local $Label1 = GUICtrlCreateLabel("IP Adresse", 24, 35, 55, 17)
    Local $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 96, 32, 130, 21)
    _GUICtrlIpAddress_Set($IPAddress1, @IPAddress1)

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

    Local $Label2 = GUICtrlCreateLabel("Netzwerk", 24, 91, 49, 17)
    Switch StringLeft(@IPAddress1, 9)
    Case '192.168.1'
    Local $Input1 = GUICtrlCreateInput("Netz 1", 96, 88, 129, 21)
    Case '192.168.2'
    Local $Input1 = GUICtrlCreateInput("Netz 2", 96, 88, 129, 21)
    Case '192.168.3'
    Local $Input1 = GUICtrlCreateInput("Netz 3", 96, 88, 129, 21)
    Case '192.168.4'
    Local $Input1 = GUICtrlCreateInput("Netz 4", 96, 88, 129, 21)
    Case '192.168.5'
    Local $Input1 = GUICtrlCreateInput("Netz 5", 96, 88, 129, 21)
    Case '192.168.6'
    Local $Input1 = GUICtrlCreateInput("Netz 6", 96, 88, 129, 21)
    Case '192.168.7'
    Local $Input1 = GUICtrlCreateInput("Netz 7", 96, 88, 129, 21)
    Case '192.168.8'
    Local $Input1 = GUICtrlCreateInput("Netz 8", 96, 88, 129, 21)
    Case '172.17.21'
    Local $Input1 = GUICtrlCreateInput("Netz 9", 96, 88, 129, 21)
    EndSwitch
    Switch StringLeft(@IPAddress1, 7)
    Case '172.17.'
    Local $Input1 = GUICtrlCreateInput("Netz 10", 96, 88, 129, 21)
    Case '172.18.'
    Local $Input1 = GUICtrlCreateInput("Netz 11", 96, 88, 129, 21)
    Case '172.19.'
    Local $Input1 = GUICtrlCreateInput("Netz 12", 96, 88, 129, 21)
    Case '172.20.'
    Local $Input1 = GUICtrlCreateInput("Netz 13", 96, 88, 129, 21)
    Case '172.21.'
    Local $Input1 = GUICtrlCreateInput("Netz 14", 96, 88, 129, 21)
    Case '172.22.'
    Local $Input1 = GUICtrlCreateInput("Netz 15", 96, 88, 129, 21)
    Case '172.23.'
    Local $Input1 = GUICtrlCreateInput("Netz 16", 96, 88, 129, 21)
    Case '172.24.'
    Local $Input1 = GUICtrlCreateInput("Netz 17", 96, 88, 129, 21)
    Case '172.25.'
    Local $Input1 = GUICtrlCreateInput("Netz 18", 96, 88, 129, 21)
    EndSwitch

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

    Local $Button1 = GUICtrlCreateButton("Exit", 120, 136, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    Local $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE or $msg = $Button1
    ExitLoop
    EndSelect
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von Apocsis (5. November 2009 um 11:54)

  • Hallo
    bist schon auf dem richtigen Weg.
    Ini - Datei
    [Netz]
    1= IP-Adresse
    2= IP-Adresse
    anschließend muß nur noch hinter

    [autoit]

    case iniread("Pfad\Ini-Datei","Netz", "1","Ip-Adresse")

    [/autoit]


    rein
    Gruß Ralf

    • Offizieller Beitrag

    Ich würde das etwas anders angehen. Die Inidatei in etwa so:

    Code
    [Bereiche]
    Netz1=192.168.1
    Netz2=192.168.2
    Netz3=192.168.3
    Netz10=172.17


    und das Script dann so:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiIPAddress.au3>
    #include <Array.au3>

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

    $aIPBereiche = IniReadSection('test.ini', 'Bereiche')
    ;~ _ArrayDisplay($aIPBereiche)

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

    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("Form1", 314, 179, 192, 114)
    Local $Label1 = GUICtrlCreateLabel("IP Adresse", 24, 35, 55, 17)
    Local $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 96, 32, 130, 21)
    _GUICtrlIpAddress_Set($IPAddress1, @IPAddress1)

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

    Local $Label2 = GUICtrlCreateLabel("Netzwerk", 24, 91, 49, 17)
    Local $Input1 = GUICtrlCreateInput("Netz nicht bekannt", 96, 88, 129, 21)
    For $i = 1 To $aIPBereiche[0][0]
    If StringLeft(@IPAddress1, StringLen($aIPBereiche[$i][1])) = $aIPBereiche[$i][1] Then
    GUICtrlSetData($Input1, $aIPBereiche[$i][0])
    ExitLoop
    EndIf
    Next
    Local $Button1 = GUICtrlCreateButton("Exit", 120, 136, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $Button1
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Hi Oscar...genau das habe ich gesucht !!! VIELEN DANK...funktioniert prima !!! Dank auch an Ralf !!