It is currently March 29th, 2024, 3:55 pm

VPN notification

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: VPN notification

Post by balala »

LNK wrote:I have a similar question, but at the other end. On my VPN, the IP always starts with 10.xxxxx. How can I extract the first part of the string to test it? I've thought of things like Webparser, but you have to give it a front marker to start from, and I don't have one. I think I need something like 'start from position 1, go to the first . and take everything in-between".

Ivan - my "VPN on" and "VPN off" IP addresses are hugely different, not just different in the last set of numbers. I wonder if you are looking at the right thing? (but that could just be how your VPN works - I look at the local IP address I get assigned by the VPN software.).
Maybe you could try with this string measure:

Code: Select all

[MeasureString]
Measure=string
String=[MeasureNetwork]
RegExpSubstitute=1
Substitute="^(.*)\.(.*)\.(.*)\.(.*)$":"\1"
IfCondition=([MeasureString]=10)
IfTrueAction=[...]
IfFalseAction=[...]
DynamicVariables=1
In the IfTrueAction and IfFalseAction, you have to use the desired bangs.
User avatar
Ivan
Posts: 258
Joined: January 27th, 2012, 6:37 pm
Location: Belgrade, Serbia

Re: VPN notification

Post by Ivan »

Working code for my skin:

THANKS TO balala

Code: Select all

[Rainmeter]
Author=Ivan...http://deivantan.deviantart.com
Update=500
MouseActionCursor=0
BackgroundMode=1
DynamicWindowSize=1

[Metadata]
Name=VPN notification
Description=VPN notification
Instructions=Change first two parts of IP in MeasureString to first two parts of your IP when you are on VPN.
Version=0.1
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

;........................................................................
;Variables
;........................................................................

[Variables]
FontColorText=888888
FontColorLabel=f2f2f2
FontFace=Papyrus
FontSizeLabel=15
FontSizeText=12
StringEffect=SHADOW
FontEffectColor=3a3a3a

;........................................................................
;Measures
;........................................................................

[MeasureLAN]
Measure=Plugin
Plugin=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=0
UpdateDivider=5
StringIndex=1

[MeasureString]
Measure=string
String=[MeasureLAN]
RegExpSubstitute=1
Substitute="^(.*)\.(.*)\.(.*)\.(.*)$":"\1.\2"
IfCondition=([MeasureString]=123.12)
IfTrueAction=[!HideMeter "Text2"][!ShowMeter "Text1"][!Redraw]
IfFalseAction=[!HideMeter "Text1"][!ShowMeter "Text2"][!Redraw]
DynamicVariables=1

;........................................................................
;Meters
;........................................................................

[Text]
Meter=STRING
X=0
Y=0
SolidColor=0,0,0,1
FontFace=#FontFace#
FontSize=20
FontColor=#FontColorText#
StringAlign=LEFT
StringEffect=#StringEffect#
FontEffectColor=#FontEffectColor#
Text="VPN is"
AntiAlias=1

[Text1]
Meter=STRING
X=R
Y=0
SolidColor=0,0,0,1
FontFace=#FontFace#
FontSize=20
FontColor=#FontColorLabel#
StringAlign=LEFT
StringEffect=#StringEffect#
FontEffectColor=#FontEffectColor#
Text="ON"
AntiAlias=1
Hidden=1

[Text2]
Meter=STRING
X=R
Y=0
SolidColor=0,0,0,1
FontFace=#FontFace#
FontSize=20
FontColor=#FontColorLabel#
StringAlign=LEFT
StringEffect=#StringEffect#
FontEffectColor=#FontEffectColor#
Text="OFF"
AntiAlias=1
Hidden=1

LNK
Posts: 3
Joined: January 31st, 2015, 2:06 pm

Re: VPN notification

Post by LNK »

Thanks to balala from me as well.

It didn't quite work as they suggested (it dropped through to the blue section and never changed), but the substitution bit did work, so I just had to move things around a little.

My final skin -

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,90

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=0
RegExpSubstitute=1
Substitute="^(.*)\.(.*)\.(.*)\.(.*)$":"\1"


[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfBelowValue = 11
IfBelowAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!Redraw]
IfAboveValue = 11
IfAboveAction=[!SetOption MeterNetwork FontColor 255,0,0,255][!Redraw]
DynamicVariables=1



[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=0,0,255,255
StringStyle=Bold
AntiAlias=1
Text=VPN
VPN on - first part of IP address is always 10
VPN 0ff - first part of IP address is over 100
So using 11 as the above/below point works fine.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: VPN notification

Post by balala »

Glad if I could help to both of you.
User avatar
gt57
Posts: 13
Joined: August 31st, 2009, 4:02 am

Re: VPN notification

Post by gt57 »

Old topic but I thought this might be relevant. Tested with Cisco AnyConnect v4.x.

In the registry, a value changes when a VPN toggles between connected and disconnected. This is the MTU value found at:
HKLM\SYSTEM\ControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\<index#>

You need to find the index number (0000, 0001, 0002, etc) for the VNP adapter. In the attached picture, this shows it to be 0001. I have other systems were it is 0003 and 0004. Easy way to find is to start at the key above and search for VPN.

The value used is MTU. When the VPN is disconnected, this will equal 1500. When a VPN is connected, this will be less than 1500. Thus, a simple IfCondition check

Sample code:
VPNRegIndex=0001

[MeasureVPN_MTU]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\#VPNRegIndex#
RegValue=MTU
IfCondition=MeasureVPN_MTU = 1500
IfTrueAction=!HideFade <something>
IfFalseAction=!ShowFade <something>
UpdateDivider=3
You do not have the required permissions to view the files attached to this post.
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: VPN notification

Post by brax64 »

well, this is my take on the topic:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1


[Variables]
	
DefaultIP=xxx.xxx.xxx.xxx
RD=[!Redraw]
SO=!SetOption
UMT=!UpdateMeter
FontColor=255,255,255
FontFace=Arial


;;====================================================
;;  Measures
;;====================================================

[WAN]
Measure=WebParser
URL=https://api.ipify.org/
RegExp=(.*)
StringIndex=1
UpdateRate=60
IfMatchMode=1
IfMatch=#DefaultIP#
IfMatchAction=[#SO# VPNIcon ImageName #@#vpn_off.png][#UMT# VPNIcon]#RD#
IfNotMatchAction=[#SO# VPNIcon ImageName #@#vpn_on.png][#UMT# VPNIcon]#RD#

;;====================================================
;;  Meters
;;====================================================

[VPNIcon]
Meter=Image
ImageName=#@#vpn.png
X=0
Y=0
W=50
H=50

[MeterWAN]
Meter=String
MeasureName=WAN
X=80
Y=0
FontSize=15
FontColor=#FontColor#
FontFace=#FontFace#
StringAlign=Left
AntiAlias=1
DynamicVariables=1
Text=%1
when you're not using a vpn, your machine has a default IP address supplied by your provider so, it should not be difficult to retrieve it; once you know it, set it as the variable "DefaultIP"... et voila'!!

In my example it set a different image if the vpn is on or off and write the IP address as text, you may choose different options though...