• Offizieller Beitrag

    Hallo!

    Vor ca 2 wochen hatte ich mal eine _setIp funktion geschrieben und hab gehört das sie hier gebraucht wird ;) also hab ich sie einfach mal reingestellt =)

    _SetIP

    Spoiler anzeigen
    [autoit]

    $sCon_name = "LAN-Verbindung";Your Conection name ( This is the GERMAN standart.. You may correct this!!!)
    $sSetipadrr = "192.168.0.2";Your IP
    $sSetmask = "255.255.255.0"; Your Mask
    $sSetgetw = "192.168.0.1"; Your (Standart) Getway
    $sSetdns = "192.168.0.1"; Your (Standart) Getway

    $_setip = _SetIp($sCon_name,$sSetipadrr,$sSetmask,$sSetgetw,1,$sSetdns)
    $error = @error
    If $error Then
    If $error = "1" Then
    MsgBox(16,"_SetIP Error","netsh.exe not exists!")
    ElseIf $error = "2" Then
    MsgBox(16,"_SetIP Error","netsh can't change. Code:"&@CRLF&$_setip)
    EndIf
    Else
    MsgBox(0,"_SetIP (By GtaSpider) Test",$_setip)
    EndIf

    ;===============================================================================
    ;
    ; Description: :Sets the Ip, the mask and the gatway
    ; Parameter(s): :$sCon_name: Connection name
    ; $sSetipadrr: The ip adress to set
    ; $sSetmask: The Mask to set
    ; $sSetgetw: The (Standart) getway to set
    ; [$nReturn: If you want that he Return the status (it maybe takes a little bit more time.)]
    ; [$sSetdns: Set the Standart DNS Server IP.)]
    ; Requirement: :netsh.exe
    ; Return Value(s): :The Stdoutread of netsh.exe
    ; User CallTip: :-
    ; Author(s): :GtaSpider
    ; Note(s): :This UDF is by GtaSpider! For more questions: em@il: [email='GtaSpider@gmx.de'][/email] or ICQ: 213827316 [GtaSpider] or ask at https://autoit.de/www.autoit.de
    ;
    ;===============================================================================

    Func _SetIp($sCon_name,$sSetipadrr,$sSetmask,$sSetgetw,$nReturn = 1,$sSetdns = "")
    $netsh = @SystemDir&"\netsh.exe"
    If @OSTYPE <> "WIN32_NT" Then $netsh = @ScriptDir&"\netsh.exe"
    If Not FileExists($netsh) Then Return SetError(1,0,0); If netsh.exe not exists then Return error code 1
    $pid = Run($netsh&' interface ip set address name="'&$sCon_name&'" source=static addr='&$sSetipadrr&' mask='&$sSetmask&' gateway='&$sSetgetw&' gwmetric=1',@WindowsDir,@SW_HIDE,2); Here it sets the adresses
    While ProcessExists($pid); till Process exist
    Sleep(100)
    WEnd
    $status = StdoutRead($pid);read the StdOut
    If StringLeft($status,3) <> "OK." Then Return SetError(2,0,$status);If error Then Return error code 2
    If $sSetdns <> "" Then
    $pid = Run($netsh&' interface ip set dns name="'&$sCon_name&'" static '&$sSetdns,@WindowsDir,@SW_HIDE,2); Get informations
    While ProcessExists($pid); till Process exist
    Sleep(100)
    WEnd
    $status = StdoutRead($pid);read the StdOut
    If StringLeft($status,3) <> "OK." Then Return SetError(2,0,$status);If error Then Return error code 2
    EndIf
    If $nReturn Then
    $pid = Run($netsh&' interface ip show address name="'&$sCon_name,@WindowsDir,@SW_HIDE,2); Get informations
    While ProcessExists($pid); till Process exist
    Sleep(100)
    WEnd
    $status = StdoutRead($pid); Set Return Value "$status"
    If $sSetdns <> "" Then
    $pid = Run($netsh&' interface ip show dns name="'&$sCon_name,@WindowsDir,@SW_HIDE,2); Get informations
    While ProcessExists($pid); till Process exist
    Sleep(100)
    WEnd
    $status &= StdoutRead($pid); Set Return Value "$status"
    EndIf
    $IsCon=DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)
    If $IsCon[0] = 0 Then TrayTip("","Warning: Can't connect to internet! Maybe you have insert a false DNS Server",2,2)
    Return $status
    EndIf
    Return 1
    EndFunc

    [/autoit]

    Mfg Spider

    Edit: Hab mal den Code etwas verändert so das es auch für 95/98/ME user funktioniert. Wenn du so einer bist einfach die netsh.exe vom anhang in dein @ScriptDir kopieren! (thx BASICOS)
    Ausserdem noch ein kleinen rechtschreib fehler korriegiert (thx Daniel w.)

    Edit2:

    • Ein paar bugs wurden entfernt
    • Standart DNS Server kann verändert werden dank $sSetdns! (Danke für die Idee an g-force (german-Nlite))
  • Nice, aber

    Code
    You maybe correct this!!!


    ist falsch ^^ Richtig wäre:

    Code
    You may correct this!!!
    oder
    You maybe have to correct this!!!

    ^^

    Einmal editiert, zuletzt von Daniel W. (10. November 2006 um 23:45)

  • ;)
    Das groesste vorteil ist dass Beide sind sehr tief super getestet .. so die funktionieren.

    Sie sind nicht mit gui sonder mit file.ini(windows xp), oder msgbox(win 98).

    Eventuel in windows 98 version such mal die Titlen vom NetzwerkKonfiguration Fenster, einfach die Titlen zum Deutsch aktualizieren.

    nicht vergessen entweder mit 3.1 kompilieren oder neue Funktionen Syntax aktualisieren.

    Einmal editiert, zuletzt von BasicOs (11. November 2006 um 15:23)