Internetverbindung trennen

  • Heyho Com 8o

    Also.
    Ein Bekannter hat gefragt, ob ich ein Programm machen könnte, wo nach einer bestimmten Zeit die Internetverbindung trennt.
    Abfrage der Zeit usw geht klar, aber wie kann ich die Verbindung zum Internet trennen?

    Ich hab schon gesucht, aber nur Lösungen über die CMD gefunden, die aber nicht klappen -.-

    Daten zum PC:

    Windows XP
    Lan-Verbindung
    Speedport w503v

    Ich hoffe, ihr versteht was ich meine ;)

    PS: Nur von diesem PC soll das Inet getrennt werden, nicht das Router abschalten!

    [autoit]


    While $Life = True
    $nMSG = BrainGetMsg()
    Switch $nMSG
    Case $Idea
    _Convert_Idea2Code()
    EndSwitch
    WEnd

    [/autoit]
  • Hi,
    um zu verhindern, daß Programme ungefragt Verbindung mit dem Internet aufnehmen, reicht es mir, dem Router im LAN eine neue IP zu geben, die im LAN nicht erreicht werden kann..
    Du könntest das Skript natürlich auch so umbauen, daß der Rechner sich aus dem LAN ausklinkt(also eine andere IP erhält), aber ich weiß nicht, ob das so gewollt ist ^^
    Ist ja auch egal, hier ein Skript, das unter XPSP3 funktioniert/funktionieren sollte ;)

    Spoiler anzeigen
    [autoit]


    #NoTrayIcon
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=G:\Grafik\Gateway.ico
    #AutoIt3Wrapper_outfile=D:\Usr\ChgGateway.Exe
    #AutoIt3Wrapper_UseUpx=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    ; Erstellt von AutoIt Scriptomatic
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    Opt('MustDeclareVars', 0) ;0=ohne, 1=erfordert Variablen-Deklaration
    ;+----------------------------------------------------------------------------+
    ;| Header: Bestimmen der Übergabeparameter |
    ;| ( Alles Strings(!!!), bis auf $ArgC ) |
    ;| FontAnzeigeCheck: |Il1 sind Alt-0124, Großes i, Kleines L, Eins |
    Const $Autor='ChgGateway.au3 ©2010 by ytwinky, MD'; |
    ;| EMail: [email='PIII1kSystem-AutoIt3Forum@yahoo.de'][/email] |
    ;| AutoIt3-Version: 3.3.0.0 |
    ;| Editor: SciTE 1.78, feste Schriftart |
    ;| Zweck : GatewayIP ändern, um Internetzugriff zu verhindern |
    ;| Tab auf 2 setzen wg. Lesbarkeit |
    ;+----------------------------------------------------------------------------+
    Const $IniName=StringLeft(@ScriptFullPath, StringInstr(@ScriptFullPath, '.', 0, -1)) &'Ini'
    Const $RegKey='HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\Always\', $du='Admin'
    Const $red=0xFF0000, $green=0x008000, $yellow=0xEEEE40, $Connected[2]=[$red, $green], $Bedingung=' where index=1'
    Const $wbemFlagReturnImmediately=0x10, $wbemFlagForwardOnly=0x20, $wbemFlags=0x10+0x20, $Checked[2]=[$GUI_UNCHECKED, $GUI_CHECKED]
    Const $strComputer='localhost'
    Const $Class1='Win32_NetworkAdapter', $Class2='Win32_NetworkAdapterConfiguration'
    Global $EachItem, $Items='', $s='', $LANVerbindung, $i, $AnzDNS, $DNSServer, $Wins1, $Wins2, $ChgGateway, $btnPing0, $btnPing1
    Global $s='', $WMISvc, $GatewayIP='', $HostIP='', $lblStatusColor, $IPSubnet, $rbStatus1, $btnQuit, $allowed
    Global $lblHostIP, $lblGatewayIP, $lblConnectionColor, $i, $lblHostIP, $lblGatewayIP, $rbStatus[2], $Gateway[2]
    $Gateway[0]=IniRead($IniName, 'Gateway', 'Aus', '192.168.1.1')
    $Gateway[1]=IniRead($IniName, 'Gateway', 'An' , '192.168.2.1')
    $WMISvc=ObjGet('winmgmts:\\' &$strComputer &'\root\cimv2')
    $Items=$WMISvc.ExecQuery('Select ProductName,MACAddress,NetConnectionID From ' &$Class1 &$Bedingung, 'wql', $wbemFlags)
    If IsObj($Items) Then
    For $EachItem In $Items
    With $EachItem
    $s&='Netzkarte: ' &.ProductName &@CrLf
    $s&='MAC-Adresse: ' &.MACAddress &@CrLf
    $LANVerbindung=.NetConnectionID
    EndWith
    Next
    EndIf
    $Items=$WMISvc.ExecQuery('Select IPSubnet,DefaultIPGateway,DNSServerSearchOrder,WINSPrimaryServer,WINSSecondaryServer From ' &$Class2 &$Bedingung, 'wql', $wbemFlags)
    If IsObj($Items) Then
    For $EachItem In $Items
    With $EachItem
    $IPSubnet=.IPSubnet(0)
    $HostIP=@IPAddress1
    $GatewayIP=.DefaultIPGateway(0)
    $DNSServer=.DNSServerSearchOrder
    $AnzDNS=UBound($DNSServer)
    If $AnzDNS=0 Then $s&='Ooops, KEIN DNS-Server eingetragen..'
    $Wins1=.WINSPrimaryServer
    $Wins2=.WINSSecondaryServer
    EndWith
    Next
    Else
    Msgbox(0, 'WMI-Ausgabe', 'Keine WMI-Objekte gefunden für Klasse: ' &$Class2)
    EndIf
    #Region ### START Koda GUI section ### Form=D:\Sprachen\AutoIt3\Au3\kxf\chggateway.kxf
    $ChgGateway=GUICreate('ChgGateway', 287, 246, 192, 114)
    $main=GUICtrlCreateGroup('', 0, -4, 285, 249)
    GUICtrlSetColor(-1, 0x000000)
    $lblChgGateway=GUICtrlCreateLabel('ChgGateway', 6, 14, 197, 41)
    GUICtrlSetFont(-1, 24, 800, 0, 'Arial')
    GUICtrlSetColor(-1, 0x000080)
    GUICtrlSetTip(-1, '©2010 by ytwinky, MD')
    $grpStatus=GUICtrlCreateGroup('Status', 230, 4, 49, 51)
    GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
    $lblStatusColor=GUICtrlCreateLabel('n', 239, 19, 34, 34)
    GUICtrlSetFont(-1, 22, 800, 0, 'Webdings')
    GUICtrlSetColor(-1, $yellow)
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    $lblHost=GUICtrlCreateLabel('Host', 6, 70, 32, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    GUICtrlSetTip(-1, 'Subnet-Mask=')
    $efHostIP=GUICtrlCreateInput($HostIP, 110, 70, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingH0=GUICtrlCreateLabel('', 235, 69, 11, 21)
    GUICtrlSetTip(-1, '127.0.0.1')
    $lblPingH1=GUICtrlCreateLabel('', 247, 69, 11, 21)
    GUICtrlSetTip(-1, 'localhost')
    $lblPingH2=GUICtrlCreateLabel('', 259, 69, 11, 21)
    GUICtrlSetTip(-1, 'HostIP')
    $lblPingH3=GUICtrlCreateLabel('', 270, 69, 12, 21)
    GUICtrlSetTip(-1, 'HostName')
    $lblGateway=GUICtrlCreateLabel('Gateway', 6, 92, 57, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    GUICtrlSetTip(-1, 'Subnet-Mask=')
    $efGWIP=GUICtrlCreateInput($GatewayIP, 110, 92, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingGW=GUICtrlCreateLabel('', 235, 91, 15, 21)
    $btnPingGW=GUICtrlCreateButton('Ping', 248, 89, 32, 21, $WS_GROUP)
    GUICtrlSetFont(-1, 8, 800, 0, 'MS Sans Serif')

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

    $lblDNSServer0=GUICtrlCreateLabel('DNS-Server1', 6, 116, 84, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $efDNS0=GUICtrlCreateInput($DNSServer[0], 110, 116, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingDNS0=GUICtrlCreateLabel('', 235, 115, 15, 21)
    $btnPing0=GUICtrlCreateButton('Ping', 248, 112, 32, 21, $WS_GROUP)
    GUICtrlSetFont(-1, 8, 800, 0, 'MS Sans Serif')

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

    $lblDNSServer1=GUICtrlCreateLabel('DNS-Server2', 6, 138, 84, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $efDNS1=GUICtrlCreateInput($DNSServer[1], 110, 138, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingDNS1=GUICtrlCreateLabel('', 235, 137, 15, 17)
    $btnPing1=GUICtrlCreateButton('Ping', 248, 135, 32, 21, $WS_GROUP)
    GUICtrlSetFont(-1, 8, 800, 0, 'MS Sans Serif')

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

    $lblWinsServer1=GUICtrlCreateLabel('WINS primär', 6, 162, 80, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    If $Wins1='' Then GUICtrlSetState(-1, $GUI_Disable)
    $efWins1=GUICtrlCreateInput($Wins1, 110, 162, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingWins1=GUICtrlCreateLabel('', 235, 161, 15, 21)

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

    $lblWinsServer2=GUICtrlCreateLabel('WINS sekundär', 6, 184, 98, 20)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    If $Wins2='' Then GUICtrlSetState(-1, $GUI_Disable)
    $efWins2=GUICtrlCreateInput($Wins1, 110, 184, 121, 24, BitOR($ES_AUTOHSCROLL, $ES_READONLY), 0)
    GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
    $lblPingWins2=GUICtrlCreateLabel('', 235, 183, 15, 21)

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

    $grpSetStatus=GUICtrlCreateGroup('Status setzen', 6, 210, 193, 31)
    $rbStatus[0]=GUICtrlCreateRadio('getrennt', 8, 222, 77, 17)
    GUICtrlSetFont(-1, 10, 800, 0, 'MS Sans Serif')
    GUICtrlSetColor(-1, 0xFF0000)
    $rbStatus[1]= GUICtrlCreateRadio('verbunden', 102, 222, 91, 17)
    GUICtrlSetFont(-1, 10, 800, 0, 'MS Sans Serif')
    GUICtrlSetColor(-1, 0x008000)
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    $btnQuit=GUICtrlCreateButton('Quit', 204, 216, 75, 25, $WS_GROUP)
    GUICtrlSetFont(-1, 8, 800, 0, 'MS Sans Serif')
    GUICtrlSetTip(-1, 'fertich..')
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    GUICtrlSetState($btnQuit, $GUI_Focus)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    ColorPing(StringLeft($HostIP, 9)=StringLeft($GatewayIP, 9))
    While 1
    $nMsg=GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $btnQuit
    IniWrite($IniName, 'Gateway', 'Aus', $Gateway[0])
    IniWrite($IniName, 'Gateway', 'An' , $Gateway[1])
    Exit
    Case $btnPingGW
    PingColor($GatewayIP, $lblPingGW)
    Case $btnPing0
    PingColor($DNSServer[0], $lblPingDNS0)
    Case $btnPing1
    PingColor($DNSServer[1], $lblPingDNS1)
    Case $rbStatus[0], $rbStatus[1]
    $i=GUICtrlRead($rbStatus[1])=$Checked[1]
    GUICtrlSetState($rbStatus[$i], $Checked[0])
    GUICtrlSetColor($lblStatusColor, $yellow)
    $i=@SystemDir &'\netsh.exe interface ip set address name="' &$LANVerbindung &'" gateway="' &$Gateway[$i] &'" gwmetric=0'
    If IsAdmin() Then
    RunWait($i, '', @SW_Minimize)
    Else
    RunAsWait($du, @ComputerName, RegRead($RegKey &$du, ''), 0, $i, '', @SW_Minimize)
    EndIf
    $Items=$WMISvc.ExecQuery('Select DefaultIPGateway,IPAddress From Win32_NetworkAdapterConfiguration' &$Bedingung, 'wql', $wbemFlags)
    For $EachItem In $Items
    $GatewayIP=$EachItem.DefaultIPGateway(0)
    $HostIP=$EachItem.IPAddress(0)
    ExitLoop
    Next
    GUICtrlSetData($lblHostIP, $HostIP)
    GUICtrlSetData($efGWIP, $GatewayIP)
    ColorPing(StringLeft($HostIP, 9)=StringLeft($GatewayIP, 9))
    EndSwitch
    WEnd

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

    ;<AutoItFunctions>
    Func ColorPing($i)
    GUICtrlSetState($rbStatus[$i], $Checked[1])
    PingColor('127.0.0.1', $lblPingH0)
    PingColor('localhost', $lblPingH1)
    PingColor(@ComputerName, $lblPingH2)
    PingColor(@IPAddress1, $lblPingH3)
    PingColor($GatewayIP, $lblPingGW)
    GUICtrlSetData($lblPingDNS0, '')
    GUICtrlSetData($lblPingDNS1, '')
    If $Wins1<>'' Then PingColor($Wins1, $lblPingWINS1)
    If $Wins2<>'' Then PingColor($Wins2, $lblPingWINS2)
    GUICtrlSetColor($lblStatusColor, $Connected[$i])
    EndFunc

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

    Func PingColor($Host, $Where)
    Local $Char[2]=['r', 'q'], $PingStatus
    $PingStatus=Ping($Host, 1)<>0
    GuiCtrlSetData($Where, $Char[$PingStatus])
    GUICtrlSetFont($Where, 10, 400, 0, 'Webdings')
    GUICtrlSetColor($Where, $Connected[$PingStatus])
    EndFunc
    ;</AutoItScript>

    [/autoit]


    Wenn es dir hilft, bau es für deine Zwecke doch einfach um..
    Ach so, ich vergaß: vergiß CMD :rofl:
    Lies dir ruhig die Beschreibung zum Befehl NethSh.Exe durch, denn damit funktioniert das Ganze..
    ..bei mir zumindest prima ;)
    Das ist aber auch kein Wunder, da ich statische IPs verwende.
    Gruß
    ytwinky

    (Ich) benutze stets die aktuelle (Beta) und SciTE..

  • bau doch einfach:

    [autoit]

    #include <Process.au3>
    _RunDOS("ipconfig /release")

    [/autoit]

    in das Skript ein. Das Skript muss natürlich am entsprechenden PC installiert werden, Wieder verbinden kannst du mit

    [autoit]

    #include <Process.au3>
    _RunDOS("ipconfig /renew")

    [/autoit]

    i

    mfg autoBert