It is currently May 27th, 2020, 3:10 am

Colored WAN IP

Help with creating, editing & fixing problems with skins
ymurawski
Posts: 3
Joined: May 18th, 2020, 5:34 pm

Colored WAN IP

Post by ymurawski »

Hello,
tnks for your help.
I have a skin wich shows my WAN IP. Im using a VPN and sometimes the VPN disconnects randomly.

I would like it, if my skins change the Font Color to red if my VPN is disconnected.

MY ISP is always something like 2.101.1.....
MY VPN Adress is something like 152.21.2....

Is it possible to change the color if the IP Value is below 100....

And is it possible to load the skin/ip faster ? it takes 1min at start to load the WAN ip.

Thanks alot :)

Code: Select all

;***********************************************
; SysInfo WAN-Left File
;***********************************************

[Rainmeter]
Update=1000

[Metadata]
Name=SysInfo
Author=Eric Miller
Information=Shows Current WAN or External IP|Takes 1 minute for data to load
Version=1.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
@include=#SKINSPATH#SysInfo\SysInfoSettings.inc

[WANGather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://checkip.dyndns.org
StringIndex=1
RegExp="(?siU)Address: (.*)</body>"
Substitute="":"N/A"
UpdateRate=3600

[TitleString]
Meter=String
X=0
Y=0
W=200
H=#BoxHeight#
FontFace=#Font#
FontSize=#FontHeight#
FontColor=#TitleColor#
SolidColor=#MouseBiteColor#
StringStyle=Bold
AntiAlias=#AntiA#
Text="WAN"
UpdateDivider=-1

[DataString]
Meter=String
MeasureName=WANGather
X=30
Y=0
FontFace=#Font#
FontColor=#DataColor#
FontSize=#FontHeight#
AntiAlias=#AntiA#
Text="%1"
UpdateDivider=60
User avatar
jsmorley
Developer
Posts: 20650
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Colored WAN IP

Post by jsmorley »

I wouldn't do it that way, based on IP address. I don't think that is certain.

I would use the Adapter Name of the currently active network adapter, which will change when you are on your VPN.

Code: Select all

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

[Variables]
VPNAdapterName=TAP-NordVPN Windows Adapter V9

[MeasureAdapterDesc]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
UpdateDivider=5
DynamicVariables=1
IfMatch=#VPNAdapterName#
IfMatchAction=[!SetOption MeterIPWeb FontColor 255,0,0,255][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterIPWeb FontColor 255,255,255,255][!UpdateMeter *][!Redraw]

[MeasureIPWeb]
Measure=WebParser
URL=https://checkip.amazonaws.com/
RegExp=(?siU)^(.*)$
StringIndex=1
UpdateRate=30
RegExpSubstitute=1
Substitute="^$":"None"

[MeterIPWeb]
Meter=String
MeasureName=MeasureIPWeb
FontSize=11
FontWeight=400
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

If you run this skin one time as is, with your VPN active, you can find the name of the TAP adapter in About / Skins in Rainmeter:



1.jpg


Then just change:

VPNAdapterName=TAP-NordVPN Windows Adapter V9
You do not have the required permissions to view the files attached to this post.
ymurawski
Posts: 3
Joined: May 18th, 2020, 5:34 pm

Re: Colored WAN IP

Post by ymurawski »

I always use the same Network Interface.
My VPN Service is directly running on my Router .

Thats wy i need to checkt it with the IP :(
User avatar
jsmorley
Developer
Posts: 20650
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Colored WAN IP

Post by jsmorley »

ymurawski wrote:
May 18th, 2020, 5:58 pm
I always use the same Network Interface.
My VPN Service is directly running on my Router .

Thats wy i need to checkt it with the IP :(

Code: Select all

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

[Variables]

[MeasureIPWeb]
Measure=WebParser
URL=https://checkip.amazonaws.com/
RegExp=(?siU)^(.*)$
StringIndex=1
UpdateRate=30
RegExpSubstitute=1
Substitute="^$":"None"

[MeasureFirstOctet]
Measure=String
String=[MeasureIPWeb]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(?siU)^(.*)\..*$":"\1"
IfCondition=[MeasureFirstOctet] < 100
IfTrueAction=[!SetOption MeterIPWeb FontColor 255,0,0,255][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterIPWeb FontColor 255,255,255,255][!UpdateMeter *][!Redraw]

[MeterIPWeb]
Meter=String
MeasureName=MeasureIPWeb
FontSize=11
FontWeight=400
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
ymurawski
Posts: 3
Joined: May 18th, 2020, 5:34 pm

Re: Colored WAN IP

Post by ymurawski »

Thank you so much :) it workes perfectly.
Maybe just a information for myself, how can i delete the grey text background ?
User avatar
jsmorley
Developer
Posts: 20650
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Colored WAN IP

Post by jsmorley »

ymurawski wrote:
May 18th, 2020, 6:20 pm
Thank you so much :) it workes perfectly.
Maybe just a information for myself, how can i delete the grey text background ?
That is this:

SolidColor=47,47,47,255

And if you are not going to have a background, you don't need this either:

Padding=5,5,5,5
User avatar
Mor3bane
Posts: 834
Joined: May 7th, 2016, 7:32 am

Re: Colored WAN IP

Post by Mor3bane »

Hey this is really interesting, as I also have a circumstance where my IP may be different due to living in a remote area, and it will periodically change as different ISP hubs are dynamic and there fore my IP sometimes changes - along with a 2 or 5 second drop out from connectivity.

I was wondering if some modifications to this solution my be used to incorporate an idea I got from this.

Is it possible to save an ip to a keyvalue variable in the ini or inc, then when it changes the colour of the text changes.

A long while back I was also trying to tell the difference between VPN and standard ISP. However, in the solution using what jsmorley helped me with meant the colour change would only occur with a user directed (mouse over in that old case) update/redraw. So, in other words the colour change would not happen even though the adaptor was recognised to have changed.

I did not really scour this thread for snippets, as I am a bit confused how the case of the OP and the colour is implied to be changing dynamically.

So my goal - show ip with a text meter - it has two states - IP existing (saved with keyvalue variable) and new IP. Respectively colour 1 and colour 2 which can simply be a simulacrum of a toggled state change.

Did I just implode my brain here, or is this possible?

Thanks.
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it
User avatar
jsmorley
Developer
Posts: 20650
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Colored WAN IP

Post by jsmorley »

I'm not 100% sure I entirely follow. Is what you are saying is that you currently have some IP address. You want to "write" that value to some variable using !WriteKeyValue so it is "persistent". Then, if the current IP is different than that saved one, you want to change the color of some text. Ok, that's certainly not hard at all. Then what happens going forward? Does that new IP become the "saved" one, and the color then changes back? If so, after what amount of time? If you don't have some threshold for what "new" means, then the second the IP changes, it will flash to the "new" color for one skin update, and then immediately become the "saved / old" one.

It would help if you could lay out the "logic" of what you are going for.
User avatar
Mor3bane
Posts: 834
Joined: May 7th, 2016, 7:32 am

Re: Colored WAN IP

Post by Mor3bane »

JS - you nailed it completely perfectly = meaning what you just wrote is exactly what I am trying to do.

If there is a logic circuit, I am hopeless, my brain rejects algebra or trig, beyond my persistent interest in math, I just suck at it anyways. ;p
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it
User avatar
jsmorley
Developer
Posts: 20650
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Colored WAN IP

Post by jsmorley »

Code: Select all

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

[Variables]
CurrentIP=Unknown

[MeasureIPWeb]
Measure=WebParser
URL=https://checkip.amazonaws.com/
RegExp=(?siU)^(.*)$
StringIndex=1
UpdateRate=30
RegExpSubstitute=1
Substitute="^$":"Holy crap, you have no Internet!"
FinishAction=[!EnableMeasure MeasureCheck][!UpdateMeasure MeasureCheck]

[MeasureCheck]
Measure=String
String=[MeasureIPWeb]
DynamicVariables=1
Disabled=1
UpdateDivider=-1
IfMatch=#CurrentIP#
IfNotMatchAction=[!SetVariable CurrentIP "[MeasureIPWeb]"][!WriteKeyValue Variables CurrentIP "[MeasureIPWeb]"][!SetOption MeterResult FontColor "255,0,0,255"][!UpdateMeter *][!Redraw]
IfMatchAction=[!SetOption MeterResult FontColor "255,255,255,255"][!UpdateMeter *][!Redraw]

[MeterResult]
Meter=String
MeasureName=MeasureIPWeb
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

So this will get the IP address. When it is done getting it, it will enable and update [MeasureCheck], which will test to see if it matches what is stored in the variable #CurrentIP#.

If it matches, either nothing is done, and the color just stays white, or it changes back to white if currently red.

If it does not match, which it won't the first time you run this, as I initially set #CurrentIP# to "Unknown", then it will do the following:

- Set the variable #CurrentIP# to be the IP address it just got.
- Write that same variable to the skin file, so it is "persistent" when you refresh or reload the skin.
- Set the color of the font to red.

The color will stay red until:

1) The [MeasureIPWeb] goes back out the next time to get the IP address. I have this set for every 30 seconds using UpdateRate.
2) You refresh or reload the skin.

Whatever alternative mechanism you might use to keep the text red for some period of time must be less than or equal to the value of UpdateRate, as the text will certainly turn back to white as soon as the match succeeds.

Note that it is important that [MeasureCheck] start out as "disabled", and that it is not allowed to initially execute unless told to do so by the FinishAction on the WebParser. It must not look for the answer before it asks the question. I also have UpdateDivider=-1 on the measure, as there is just no point at all in having it check this value once a second, when it simply can't change unless the WebParser measure changes.