It is currently April 25th, 2024, 2:53 pm

Enable/Disable Internet

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7164
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Enable/Disable Internet

Post by Yincognito »

Predator73 wrote: October 25th, 2020, 8:03 pm I tried but they don't work with the ipconfig / release command I get_Error: command line not recognized or incomplete.
and with ipconfig / renev equal_Error: command line not recognized or incomplete.
The proper way of using those commands is without the space after the /. So, it's
ipconfig /release and ipconfig /renew
and not
ipconfig / release or ipconfig / renew.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7164
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Enable/Disable Internet

Post by Yincognito »

jsmorley wrote: October 25th, 2020, 9:12 pm While disabling the interface will certainly disconnect you from the "WAN / internet", it will also disconnect you from your entire LAN. I wonder if there is a generic way to disable the internet while leaving you connected to other devices on your network, a printer for instance.
Take a look here. Not sure, but it might be possible for the approach to be "translated" into equivalent command lines... :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Enable/Disable Internet

Post by CodeCode »

jsmorley wrote: May 2nd, 2016, 4:11 pm

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
State=1

[MeasureToggle]
Measure=Calc
Formula=#State#
IfCondition=MeasureToggle=0
IfTrueAction=[!CommandMeasure MeasureTurnOff "Run"]
IfFalseAction=[!CommandMeasure MeasureTurnOn "Run"]
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[MeasureTurnOff]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /release
State=Hide

[MeasureTurnOn]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /renew
State=Hide

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoType=LAN_CONNECTIVITY
SysInfoData=Best
IfCondition=MeasureNetWork = -1
IfTrueAction=[!SetOption MeterWAN Text "No Network"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterWAN Text "Network OK"][!UpdateMeter *][!Redraw]

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
SysInfoData=Best
IfCondition=MeasureInternet = -1
IfTrueAction=[!SetOption MeterLAN Text "No Internet"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterLAN Text "Internet OK"][!UpdateMeter *][!Redraw]

[MeterWAN]
Meter=String
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1

[MeterLAN]
Meter=String
Y=5R
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1

[MeterToggle]
Meter=String
Y=10R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toggle
DynamicVariables=1
LeftMouseUpAction=[!EnableMeasure MeasureToggle][!SetVariable State "(1-#State#)"][!UpdateMeasure "MeasureToggle"]
GIF.gif
^^This Is Awesome!^^

Thanks to the people who have ideas, and those with the solution/s!
:rosegift:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
IsT3RiK
Posts: 1
Joined: April 30th, 2022, 7:36 am

Re: Enable/Disable Internet

Post by IsT3RiK »

hello, someone can update the code, cause the ON /OFF works but the status dosent change :D :D
thx a lot
User avatar
Yincognito
Rainmeter Sage
Posts: 7164
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Enable/Disable Internet

Post by Yincognito »

IsT3RiK wrote: April 30th, 2022, 7:39 am hello, someone can update the code, cause the ON /OFF works but the status dosent change :D :D
thx a lot
If by any chance your connection is a wifi one instead of an ethernet one, or other details regarding the DHCP and whether the IP is static or dynamic are different, then jsmorley code from this thread which is using these to release or renew the IP for all adapters:

Code: Select all

ipconfig /release

Code: Select all

ifconfig /renew
will indeed not work, or better said it will only work when you're "disconnecting" via ipconfig / release.

The solution in that case would be to either:

1) use Predator73's resolve above (though that requires elevation in CMD, aka running it as an administrator), by running these to disable or enable your network interface (again, these will not reconnect you to the internet if your connection is wireless, just like the previously mentioned method):

Code: Select all

netsh interface set interface "YOURINTERFACE" disabled

Code: Select all

netsh interface set interface "YOURINTERFACE" enabled
2) use these to disconnect or connect to your interface and wireless SSID (assuming the security key / password is automatically used):

Code: Select all

netsh wlan disconnect interface="YOURINTERFACE"

Code: Select all

netsh wlan connect name="YOURCONNECTION" ssid="YOURSSID" interface="YOURINTERFACE"
As far as I tested the last two commands, they seem to do precisely what the user does when disconnecting or connecting manually. They don't require administrative privileges either, so that's a plus. Though I am able to connect over a wired connection as well, I didn't test them on that to see if they can represent a general solution to the problem by working in that case too, but anyone is welcomed to try (by the way, parameters are generally required only if the said parameter can have more than one valid value).

To see what values can be used for the name, ssid or interface parameters / fields, these can be used (I used the same name value as the ssid value was and it worked for me):

Code: Select all

netsh wlan show profile

Code: Select all

netsh interface show interface
To apply these in the skin, test them in CMD first to make sure whichever commands you chose work, then set the Parameter= options in the RunCommand measures from the skin accordingly.

References: here, here, here and here.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Enable/Disable Internet

Post by CodeCode »

I have this code sry no rmskin for this and you'll have to write in your own colors and fonts.

Easily customized once you get it looking right for you:

Code: Select all

[Rainmeter]
Update=500
BackgroundMargins=0,0,35,35
Group=NetWiz

[Metadata]
Author=Code Sapient

[Variables]
@include=#@#RoundVariables.inc
@include2=#@#Preferences.inc
@include3=NetWizard.inc
State=0

[BackgroundOne]
Meter=Image
ImageName=#@#NewFrameBase.png
ImageAlpha=255
ImageTint=120,120,120,255
X=33
Y=32
W=274
H=274
AntiAlias=1
DynamicVariables=1
MouseOverAction=[!SetOption Rainmeter ContextTitle2 "Connection Settings"][!SetOption Rainmeter ContextAction2 """["#CURRENTPATH#NetWizard.inc"]"""]
Hidden=0

[MeterShowIn]
Meter=Shape
Shape=Rectangle 63,63,211,211,105 | Fill Color 0,0,0,0 | StrokeWidth 3 | Stroke Color #MainInColor#
Group=Bezel
Hidden=0

[MeterShowOut]
Meter=Shape
Shape=Rectangle 32,32,273,273,136 | Fill Color 0,0,0,0 | StrokeWidth 4 | Stroke Color #MainColor#
Group=Bezel
Hidden=0

[MeasureTurnOff]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /release
State=Hide

[MeasureTurnOn]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /renew
State=Hide

[MeasureNetTotal]
Measure=NetTotal
UpdateDivider=2
MinValue=-30000
MaxValue=([MeasureNetTotal]<=500000000 ? 500000000 : ([MeasureNetTotal]<=900000000 ? 900000000 : ([MeasureNetTotal]<=1500000000 ? 1500000000 : ([MeasureNetTotal]<=2500000000 ? 2500000000 : ([MeasureNetTotal]<=5000000000 ? 5000000000 : ([MeasureNetTotal]<=10000000000 ? 10000000000 : ([MeasureNetTotal]<=20000000000 ? 20000000000 : ([MeasureNetTotal]>20000000000 : (10 * 1048576)))))))) + 10000)

[MeasureNetTotalb]
Measure=NetTotal
InvertMeasure=1
UpdateDivider=2
MinValue=-30000
MaxValue=([MeasureNetTotal]<=500000000 ? 500000000 : ([MeasureNetTotal]<=900000000 ? 900000000 : ([MeasureNetTotal]<=1500000000 ? 1500000000 : ([MeasureNetTotal]<=2500000000 ? 2500000000 : ([MeasureNetTotal]<=5000000000 ? 5000000000 : ([MeasureNetTotal]<=10000000000 ? 10000000000 : ([MeasureNetTotal]<=20000000000 ? 20000000000 : ([MeasureNetTotal]>20000000000 : (10 * 1048576)))))))) + 10000)

[NetTotal]
MeasureName=MeasureNetTotal
Meter=ROUNDLINE
X=133
Y=133
W=71
H=71
StartAngle=-1.5458897
RotationAngle=6.188
LineColor=#MainFontColor#
LineLength=94
LineStart=100
Solid=1
AntiAlias=1

[NetTotalb]
MeasureName=MeasureNetTotalb
Meter=ROUNDLINE
X=133
Y=133
W=71
H=71
StartAngle=4.694
RotationAngle=-6.188
LineColor=#TotalbColor#
LineLength=97
LineStart=100
Solid=1
AntiAlias=1

[MeasureType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
RegExpSubstitute=1
Substitute="^0$":"Released"

[MeterType]
Meter=String
MeasureName=MeasureType
Fontsize=20
FontFace=#BigDriveNameFont#
FontColor=#BigDriveAltColor#
AntiAlias=1 
StringAlign=CenterCenter
StringCase=None
x=169
y=122
Text=%1
StringEffect=Border
FontEffectColor=0,0,0,255
LeftMouseDownAction=
DynamicVariables=1

[MeterShapeTop]
Meter=Shape
Shape=Rectangle 74,152,191,29,5 | Fill Color 0,0,0,210 | StrokeWidth 2 | Stroke Color #MainColor#
RightMouseUpAction=[!ToggleMeter "MeterShapeTop"][!ToggleMeter "MeterShapeBottom"][!ToggleMeter "MeterConnectivity"][!ToggleMeter "MeterTextHidden"][!UpdateMeter *][!Redraw]
LeftMouseUpAction=[ ]
Hidden=1

[MeterShapeBottom]
Meter=Shape
Shape=Rectangle 74,152,191,29,5 | Fill Color 0,0,0,210 | StrokeWidth 2 | Stroke Color #TotalbColor#
MouseLeaveAction=[!ToggleMeter "MeterShapeBottom"][!ToggleMeter "MeterConnectivity"][!ToggleMeter "MeterTextHidden"][!UpdateMeter *][!Update]
Hidden=1

[MeasureLoopbackIP]
Measure=Plugin
Plugin=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=Best
Substitute=".":""

[MeasureInterface]
Measure=Calc
UpdateDivider=1
IfCondition=(MeasureLoopbackIP = 127001)
IfTrueAction3=[!UpdateMeter MeterConnectivity]
IfCondition2=(MeasureLoopbackIP > 127001)
IfTrueAction3=[!UpdateMeter MeterConnectivity]
IfCondition3=(MeasureLoopbackIP < 127001)
IfTrueAction3=[!UpdateMeter MeterConnectivity]
DynamicVariables=1

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
SysInfoData=Best
Disabled=0
RegExpSubstitute=1
Substitute="^1$":"CONNECTED","^-1$":"OFF LINE"
OnChangeAction=[!Refresh][!Update]
DynamicVariables=1

[MeterConnectivity]
Meter=String
MeasureName=MeasureInternet
Fontsize=19
FontFace=#GlobalFont#
FontColor=#MainFontColor#
AntiAlias=1
StringAlign=CenterCenter
X=169
Y=167
Text=
MouseOverAction=[!SetOption "MeterShapeTop" "Hidden" "0"][!Update]
MouseLeaveAction=[!SetOption "MeterShapeTop" "Hidden" "1"][!Update]
RightMouseUpAction=
DynamicVariables=1

[MeterTextHidden]
Meter=STRING
FontFace=Tele-Marines
FontColor=#AltSecondaryTextColor#
FontSize=19
StringAlign=CenterCenter
X=169
Y=167
Text="Release"
SolidColor=0,0,0,1
MouseScrollUpAction=
LeftMouseUpAction=[!CommandMeasure MeasureTurnOn "Run"][!SetOption MeterTextHidden Text "Release"][!UpdateMeter *][!Update]
RightMouseUpAction=[!CommandMeasure MeasureTurnOff "Run"][!SetOption MeterTextHidden Text "Renew"][!UpdateMeter *][!Update]
Antialias=1
DynamicVariables=1
Hidden=1

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
Substitute="#IPSkinAdapterFullName#":"STANDARD","#IPSkinVPNFullName#":"Private","0":"None"
IfMatch=STANDARD
OnUpdateAction=[!UpdateMeter MeterTextAdapter]
DynamicVariables=1
IfMatchMode=1

[MeterTextAdapter]
Meter=String
MeasureName=MeasureAdapter
Fontsize=20
FontFace=#BigDriveNameFont#
FontColor=#BigDriveAltColor#
AntiAlias=1 
StringAlign=CenterCenter
StringCase=Proper
x=169
y=213
Text=
StringEffect=Border
FontEffectColor=0,0,0,255
LeftMouseDownAction=#LinkOne#
DynamicVariables=1
Hidden=0

[Lens]
Meter=Image
ImageName=#@#Lens.png 
ImageAlpha=190
X=65
Y=64
W=209
H=209

[MeasureToggle]
Measure=Calc
Formula=#State#
IfCondition=MeasureToggle=0
IfTrueAction=[!CommandMeasure MeasureTurnOff "Run"]
IfFalseAction=[!CommandMeasure MeasureTurnOn "Run"]
Disabled=1
UpdateDivider=-1
DynamicVariables=1
Here is my settings code (NetWizard.inc):

Code: Select all

[Variables]

VPNFullPath=""C:\Program Files\Private Internet Access\pia-client.exe""
MatrixFont=Hirosh
TallThinFont=VertigoFLF
IPSkinAdapterFullName="Realtek Gaming GbE Family Controller"
IPSkinVPNFullName="Private Internet Access Network Adapter"
I HOPE I helped a little. :oops:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.