General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
reset nic(for broadband users):important update
Posted by: disrupted
Date: September 02, 2009 07:44PM

http://kmext.sourceforge.net/files/niccontrol.7z

especially useful for developers and testers when you want to disable your lan and use dialup to check how a site loads on dialup or how an extension works also if you have bridged networks or intranet with multiple nics and want to disable one of them for a direct connection.

original script by someone at the autoit forums. this extension requires windows 2k and above





# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ------niccontrol----------------------------

$_tool_path=getfolder(RootFolder)."\\Tools";

niccontrol{
$nicname = ("Local Area Connection");
$nicname = prompt("Please enter local area connection you wish to reset or disable:", "Disable Connection", $nicname);
$nicname == "" ? "" : exec($_tool_path."\\niccontrol.exe " .$nicname);
}

niccontrol_BuildMenu{
setmenu("&Tools",macro,"Disable NIC",niccontrol);
}

$OnInit=$OnInit."niccontrol_BuildMenu;";
# --------------------------------------------------------------------
$macroModules=$macroModules."niccontrol;";


; Disable and Enable a Network card using 'Shell.Application'
;
; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled

#notrayicon

$oLanConnection = $CmdLineRaw; Change this to the name of the adapter to be disabled !
$bEnable = true ; Change this to 'false' to DISABLE the network adapter

if @OSType<>"WIN32_NT" then
Msgbox(0,"","This script requires Windows 2000 or higher.")
exit
endif


if @OSVersion="WIN_2000" then
$strFolderName = "Network and Dial-up Connections"
else
$strFolderName = "Network Connections"; Windows XP
endif

Select
Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,_2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
$strEnableVerb = "En&able"
$strDisableVerb = "Disa&ble"

; Add here the correct Verbs for your Operating System Language
EndSelect


;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Find 'Network connections' control panel item
$oNetConnections=""

For $FolderItem in $oControlPanel.Items
If $FolderItem.Name = $strFolderName then
$oNetConnections = $FolderItem.GetFolder
Exitloop
Endif
Next


If not IsObj($oNetConnections) Then
MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder."
Exit
EndIf


For $FolderItem In $oNetConnections.Items
If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
$oLanConnection = $FolderItem
Exitloop
EndIf
Next

If not IsObj($oLanConnection) Then
MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item.")
Exit
EndIf

$oEnableVerb=""
$oDisableVerb=""

For $Verb In $oLanConnection.Verbs
If $Verb.Name = $strEnableVerb Then
$oEnableVerb = $Verb
EndIf
If $Verb.Name = $strDisableVerb Then
$oDisableVerb = $Verb
EndIf
Next

If $bEnable then
If IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network card
Endif

If not $bEnable then
If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf

Sleep(1000)


special thanks to the author at autoit forums



Edited 1 time(s). Last edit at 09/07/2009 09:18PM by disrupted.

Options: ReplyQuote
Re: reset nic(for broadband users):important update
Posted by: disrupted
Date: September 07, 2009 09:33PM

important update, please redownload
http://kmext.sourceforge.net/files/niccontrol.7z

now you can toggle disable and enable so more convenient and more integarted in km macro.. on enable, you will not be prompted for the nic name as it will be retrieved from km prefs. a new addition is nic manager in k-meleon, which retrieves your gateway address and opens it in km to change your router/broadband connection settings. both scripts are from autoit forums.. first one i don't remember who and the second one is by 'herewasplato'. special thanks to both authors







src

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# --------nic control-------------------------

$_tool_path=getfolder(RootFolder)."\\Tools";
$_km_path=getfolder(RootFolder)."\\k-meleon.exe";

nic_tog{
menuchecked=getpref(BOOL,"kmeleon.niccontrol.active");
togglepref(BOOL,"kmeleon.niccontrol.active");
$checkava=getpref(BOOL,"kmeleon.niccontrol.active");
$disabled=("true");
$checkava==$disabled?&nicoff:&nicon;
}

nicoff{
$nicname = ("Local Area Connection");
$nicname = prompt("Please enter local area connection you wish to reset or disable:", "Disable Connection", $nicname);
$nicname == "" ? "" : exec($_tool_path."\\niccontrol.exe disable " .$nicname);
setpref(STRING,"kmeleon.niccontrol.nicname", $nicname);
$nicdisable=(" has been disabled");
$nicstatusstring=($nicname.$nicdisable);
statusbar($nicstatusstring);
}

nicon{
$nicname=getpref(STRING,"kmeleon.niccontrol.nicname");
exec($_tool_path."\\niccontrol.exe enable " .$nicname);
$nicenable=(" has been renabled");
$nicstatusstring=($nicname.$nicenable);
statusbar($nicstatusstring);
}

nicmanage{
exec($_tool_path."\\nicmanage.exe " .$_km_path);
}

niccontrol_BuildMenu{
setmenu("&Tools",macro,"Disable NIC",nic_tog);
setmenu("&Tools",macro,"Manage NIC",nicmanage);
}

$OnInit=$OnInit."niccontrol_BuildMenu;";
# --------------------------------------------------------------------
$macroModules=$macroModules."niccontrol;";


nic control: disable/enable
; Disable and Enable a Network card using 'Shell.Application'
;
; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled

#notrayicon



$oLanConnection = $CmdLine[2]; Change this to the name of the adapter to be disabled !
; Change this to 'false' to DISABLE the network adapter
if $cmdline[1]=("enable") then
$bEnable = true
elseif $cmdline[1]=("disable") then
$bEnable = false
endif
if @OSType<>"WIN32_NT" then
Msgbox(0,"","This script requires Windows 2000 or higher.")
exit
endif


if @OSVersion="WIN_2000" then
$strFolderName = "Network and Dial-up Connections"
else
$strFolderName = "Network Connections"; Windows XP
endif

Select
Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,_2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
$strEnableVerb = "En&able"
$strDisableVerb = "Disa&ble"

; Add here the correct Verbs for your Operating System Language
EndSelect


;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Find 'Network connections' control panel item
$oNetConnections=""

For $FolderItem in $oControlPanel.Items
If $FolderItem.Name = $strFolderName then
$oNetConnections = $FolderItem.GetFolder
Exitloop
Endif
Next


If not IsObj($oNetConnections) Then
MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder."
Exit
EndIf


For $FolderItem In $oNetConnections.Items
If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
$oLanConnection = $FolderItem
Exitloop
EndIf
Next

If not IsObj($oLanConnection) Then
MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item.")
Exit
EndIf

$oEnableVerb=""
$oDisableVerb=""

For $Verb In $oLanConnection.Verbs
If $Verb.Name = $strEnableVerb Then
$oEnableVerb = $Verb
EndIf
If $Verb.Name = $strDisableVerb Then
$oDisableVerb = $Verb
EndIf
Next

If $bEnable then
If IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network card
Endif

If not $bEnable then
If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf

Sleep(1000)



nic manage by herewasplato
;scriptauthor: autoitforums: herewasplato (admin): special thanks to herewasplato
;slightly modified for km
;port routing table to text file
;(or use std in/out in beta AutoIt)

#notrayicon

RunWait(@ComSpec & " /c " & 'netstat -r > c:\temp\netstatout.txt', "", @SW_HIDE)


;Read contents of file
$file1txt = FileRead('c:\temp\netstatout.txt', FileGetSize('c:\temp\netstatout.txt'))

;split to array
$file1txtARRAY = StringSplit($file1txt, @CRLF, 1)

;find/display the line of interest
$cnt = 0
For $i = 1 To $file1txtARRAY[0]
If StringInStr($file1txtARRAY[$i], "===") <> 0 Then $cnt = $cnt + 1
If $cnt = 4 Then ExitLoop
Next
;MsgBox(0, "", $file1txtARRAY[$i - 1])

;get the length of that line
$len = StringLen($file1txtARRAY[$i - 1])

;find the position of the 3rd dot from the right side
$3rdDOT = StringInStr($file1txtARRAY[$i - 1], ".", 0, -3)

;generate default gateway IP
$IP = StringRight($file1txtARRAY[$i - 1], $len - $3rdDOT + 4)

;strip any leading blanks from the first part of the IP
$IP = StringStripWS($IP, 8)
$kmproper=FileGetShortName($cmdlineraw)
$manageinkm=($kmproper & " " & $IP)
run($manageinkm)


again, this extension os for windows 2000 and above only



Edited 1 time(s). Last edit at 09/07/2009 09:39PM by disrupted.

Options: ReplyQuote
Re: reset nic(for broadband users):important update
Posted by: disrupted
Date: September 09, 2009 09:34PM

important update#2 for nic manager, download from same link

bug fix for users who might have cmd disabled for security reasons. nicmanager now reads your registry settings for cmd.. enables it anyways before calling comspec and rewrites the key according to your original set (in case it was disabled, it disables it back again)

new script
;scriptauthor: autoitforums: herewasplato (admin): special thanks to herewasplato
;slightly modified for km
;port routing table to text file
;(or use std in/out in beta AutoIt)

#notrayicon

$defcmd=RegRead("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System", "DisableCMD")
;msgbox(64, $defcmd, $defcmd)
RegWrite("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System" ,"DisableCMD", "REG_DWORD", 0)

sleep(888)


RunWait(@ComSpec & " /c " & 'netstat -r > c:\temp\netstatout.txt', "", @SW_HIDE)


;Read contents of file
$file1txt = FileRead('c:\temp\netstatout.txt', FileGetSize('c:\temp\netstatout.txt'))

;split to array
$file1txtARRAY = StringSplit($file1txt, @CRLF, 1)

;find/display the line of interest
$cnt = 0
For $i = 1 To $file1txtARRAY[0]
If StringInStr($file1txtARRAY[$i], "===") <> 0 Then $cnt = $cnt + 1
If $cnt = 4 Then ExitLoop
Next
;MsgBox(0, "", $file1txtARRAY[$i - 1])

;get the length of that line
$len = StringLen($file1txtARRAY[$i - 1])

;find the position of the 3rd dot from the right side
$3rdDOT = StringInStr($file1txtARRAY[$i - 1], ".", 0, -3)

;generate default gateway IP
$IP = StringRight($file1txtARRAY[$i - 1], $len - $3rdDOT + 4)

;strip any leading blanks from the first part of the IP
$IP = StringStripWS($IP, 8)
$kmproper=FileGetShortName($cmdlineraw)
$manageinkm=($kmproper & " " & $IP)
run($manageinkm)
RegWrite("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System" ,"DisableCMD", "REG_DWORD", $defcmd)


Options: ReplyQuote


K-Meleon forum is powered by Phorum.