It is currently October 16th, 2021, 12:38 am

substituting an IP range starting 192.168.41 or 51

General topics related to Rainmeter.
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

Sorry, I apologise.

If a person is on VPN and they get connected to the Leeds Firewall connection starting 192.168.41. They get given an IP 192.168.41.10 for example. All Leeds connections would start 192.168.41 so I would like to substitute example 192.168.41.10 as Leeds Firewall Connection

If someone got directed to our Manchester Firewall, they would get an IP starting 192.168.51 eg 192.168.51.100. So I would like to replace the full IP with Manchester Firewall Connection

Same as if some one connects from our USB Dongle they can get an IP 172.16.2.3, so I would like to substitute that IP with Mobile Connection.

Thanks

Martyn
User avatar
death.crafter
Posts: 1038
Joined: April 24th, 2021, 8:13 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by death.crafter »

nytram wrote: September 10th, 2021, 1:07 pm Sorry, I apologise.

If a person is on VPN and they get connected to the Leeds Firewall connection starting 192.168.41. They get given an IP 192.168.41.10 for example. All Leeds connections would start 192.168.41 so I would like to substitute example 192.168.41.10 as Leeds Firewall Connection

If someone got directed to our Manchester Firewall, they would get an IP starting 192.168.51 eg 192.168.51.100. So I would like to replace the full IP with Manchester Firewall Connection

Same as if some one connects from our USB Dongle they can get an IP 172.16.2.3, so I would like to substitute that IP with Mobile Connection.

Thanks

Martyn
Okay, Martin thank you for the explanations. Here, what would come to our rescue is, RegExpSubstitution.

Here, we would substitute after matching the starting indexes. It would require only one measure.
So the measure would be like:

Code: Select all

[IPAdress]
Measure=WebParser
Url=your.url
RegExpSubstitution=1
Substitute="^$":"Not connected", "^192\.168\.41\..*$":"Leeds Firewall", "192\.168\.51\..*":"Manchester Firewall", "172\.16\..*":"Mobile Connection"
Here, .(dot) donates any character. Since it's a regex reserved character, we need to escape it with \ if we need to match a literal dot.

So I just match from the beginning using ^ from the start. The rest of the characters can be anything.

If the values match, they are substituted accordingly.

You can learn more about regex from online. A good example would be https://regex101.com.

Reply if it works as expected.
from the Realm of Death
My Current Desktop
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

Hi

Thank you. I understand the logic now for expanding it.

I am currently not getting anything for it. I would expect that I get Connected to Manchester as my IP address is 192.168.51.111

Code: Select all

; Display the VPN Firewall connection location
[VPNConnectedTo]
Meter=STRING
X=120
Y=105
MeasureName=IPAddress
Antialias=1
FontFace=Arial
FontColor=255,255,255,255
FontSize=12
StringAlign=Left
StringStyle=Normal
AntiAlias=1

[IPAddress]
Measure=WebParser
Url=http://infrastructure.***/ip.php
RegExpSubstitution=1
Substitute="^$":"Not connected", "^192\.168\.41\..*$":"Leeds Firewall", "192\.168\.51\..*":"Manchester Firewall", "172\.16\..*":"Mobile Connection"
User avatar
death.crafter
Posts: 1038
Joined: April 24th, 2021, 8:13 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by death.crafter »

nytram wrote: September 10th, 2021, 5:11 pm

Code: Select all

; Display the VPN Firewall connection location
[VPNConnectedTo]
Meter=STRING
X=120
Y=105
MeasureName=IPAddress
Antialias=1
FontFace=Arial
FontColor=255,255,255,255
FontSize=12
StringAlign=Left
StringStyle=Normal
AntiAlias=1

[IPAddress]
Measure=WebParser
Url=http://infrastructure.***/ip.php
RegExpSubstitute=1
Substitute="^$":"Not connected", "^192\.168\.41\..*$":"Leeds Firewall", "192\.168\.51\..*":"Manchester Firewall", "172\.16\..*":"Mobile Connection"
Sorry, there was a typo. It's RegExpSubstitute and not tion.
from the Realm of Death
My Current Desktop
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

Hey, no problems at all.

That now says Not Connected but it should say Manchester Firewall

Thanks

Martyn
User avatar
death.crafter
Posts: 1038
Joined: April 24th, 2021, 8:13 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by death.crafter »

nytram wrote: September 10th, 2021, 5:31 pm Hey, no problems at all.

That now says Not Connected but it should say Manchester Firewall

Thanks

Martyn
Add a line Dubug=2, and check the WebParserDump.txt for what is the output you are getting. Cause it's getting nothing.
from the Realm of Death
My Current Desktop
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

Hi

Will do.

Can I confirm this line is fully correct ? There is a $ after ^192\.168\.41..*$ but none of the others have the hat ^ and the $

Code: Select all

Substitute="^$":"Not connected", "^192\.168\.41\..*$":"Leeds Firewall", "192\.168\.51\..*":"Manchester Firewall", "172\.16\..*":"Mobile Connection"
Ill run the debug now and report back

Martyn
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

I cant find the file. I will let you know when I do. It should be in Skins and the folder but I cant see it

Martyn
nytram
Posts: 13
Joined: September 9th, 2021, 10:57 am

Re: substituting an IP range starting 192.168.41 or 51

Post by nytram »

got the debug working and its the full ip address 192.168.51.111 and nothing else

thanks

Martyn
User avatar
death.crafter
Posts: 1038
Joined: April 24th, 2021, 8:13 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by death.crafter »

nytram wrote: September 10th, 2021, 6:36 pm got the debug working and its the full ip address 192.168.51.111 and nothing else

thanks

Martyn
Hmm, lemme check then
from the Realm of Death
My Current Desktop