It is currently October 18th, 2021, 10:56 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

substituting an IP range starting 192.168.41 or 51

Post by nytram »

Hi

I use the code below to get our VPN IP address from the PHP page and that works great but to make it easier. I would like to create another label on our skin that says which VPN site they are connected to

eg
192.168.41.* is England
192.168.51.* is USA

If they are on a 172.16 to 20 range then say O2 connected

If 172.120 or 130.* then they are on a satellite/remote office connection

I know you can have more than 1 substitute but I have to know the full IP address. Is there a way to do this ?

Thanks in Advance

Martyn

Code: Select all

; Get the IP address
[MeasureNetwork]
Measure=Plugin
Plugin=WebParser
URL=http://infrastructure.****/ip.php
UpdateRate=14400
RegExp=(?siU)^(.*)$
StringIndex=1
Substitute="":"Not Connected to Network"
User avatar
death.crafter
Posts: 1042
Joined: April 24th, 2021, 8:13 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by death.crafter »

If they are on a 172.16 to 20 range then say O2 connected

If 172.120 or 130.*
[/quote]

Can you be more specific about the range and the places

Like 192.172.16-20.*

If it is then,

Code: Select all

[Variables]
NetworkLocation=Unknown

[MeasureNetwork]
Measure=WebParser
URL=http://infrastructure.****/ip.php
UpdateRate=14400
RegExp=(?siU)^(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})$
StringIndex=1
Substitute="":"Not Connected to Network"

[MeasureLocation]
Measure=WebParser
Url=[MeasureNetwork]
StringIndex=3
IfCondition=(MeasureLocation>=16) && (MeasureLocation=20)
IfTrueAction=[!SetVariable NetworkLocation "O2"]
IfCondition2=(MeasureLocation=120) || (MeasureLocation=130)
IfTrueAction2=[!SetVariable NetworkLocation "Remote Desktop"]
This will, check the third section of the IP address and use IfConditions to set the location or whatever you call it. If it depends on more than that, then more processing would be required.
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 for your reply.

Each machine will only have 1 connection.

Id like to know which VPN site they are connected to

192.168.41.* is England
192.168.51.* is USA

If they are using a mobile broadband dongle with a sim in

our range is 172.16.*.*, 172.17.*.*, 172.18.*.*, 172.19.*.*.* and 172.20.*.*.*

if they are 172.20.*.* the remote site goes to one of the England offices and 172.30.*.* goes to the USA

Hope that it more clearer. If I get 1 example, then I will be able to do the rest.

Thanks in advance again

Martyn
Last edited by nytram on September 9th, 2021, 4:00 pm, edited 1 time in total.
User avatar
death.crafter
Posts: 1042
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 9th, 2021, 12:54 pm Hi

Thank you for your reply.

If 172.120 or 130.*

We have 2 locations that have different satelite offices

172.120.* report into the Leeds Network

172.130.* report into our Manchester Network

Hope that explains it a bit better

Thanks

Martyn
Ahh, then you can use just substitution:

Code: Select all

[MeasureNetwork]
Measure=WebParser
URL=http://infrastructure.****/ip.php
UpdateRate=14400
RegExp=(?siU)^(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})$
RegExpSubstitution=1
Substitute="^$":"Not Connected to Network"

[MeasureLocation]
Measure=WebParser
Url=[MeasureNetwork]
StringIndex=3
Substitute="120":"Leeds Network", "130":"Manchester Network", "":"Disconnected"
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 »

Thank you. That works a treat.

Is there a way we can search the 2nd or 3rd string ? This would open more doors for me to use it.

found we have some sites 10.36 and 172.20 and 172.30, etc

Thanks

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 tried this but its both and not either part 2 or part 3 of the IP. There will be no clashing of numbers if it can search both part 2 and 3

Thanks Martyn

Code: Select all

[MeasureNetwork]
Measure=WebParser
URL=http://infrastructure.*****/ip.php
UpdateRate=14400
RegExp=(?siU)^(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})\.?(\d{0,3})$
RegExpSubstitution=1
Substitute="^$":"Not Connected to Network"

[MeasureLocationIpPart2]
Measure=WebParser
Url=[MeasureNetwork]
StringIndex=2
Substitute="^$":"Not Connected to PFS Network",  "16": "O2", "17": "O2", "18": "O2", "20":"Old VPN Connection", "30":"Old VPN Connection" "55":"Satelite VPN Connection"

[MeasureLocationIpPart3]
Measure=WebParser
Url=[MeasureNetwork]
StringIndex=3
Substitute="41":"Leeds Firewall", "50":"Leeds Office", "51":"Manchester Firewall", "":"Not Connected to Network"


[MeasureLocation]
Meter=String
X=120
Y=105
MeasureName=MeasureLocationIpPart2
MeasureName2=MeasureLocationIpPart3
Antialias=1
FontFace=Arial
FontColor=255,255,255,255
FontSize=12
StringAlign=Left
StringStyle=Normal
AntiAlias=1
Text=%1 %2










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 also found that %1 search was pulling 16 from the ip 168 on part 2 of the IP and it should have ignored it as its 168.

I would have thought quotes would have fixed that.

Is there a way for it to search and substitute the correct number ie 168 and not 16 ?

Thanks again

Martyn
User avatar
SilverAzide
Rainmeter Sage
Posts: 1615
Joined: March 23rd, 2015, 5:26 pm

Re: substituting an IP range starting 192.168.41 or 51

Post by SilverAzide »

nytram wrote: September 10th, 2021, 11:18 am Sorry, I also found that %1 search was pulling 16 from the ip 168 on part 2 of the IP and it should have ignored it as its 168.

I would have thought quotes would have fixed that.

Is there a way for it to search and substitute the correct number ie 168 and not 16 ?

Thanks again

Martyn
Sorry to barge in here... all this sounds overly complicated. It should be fairly simple to do exactly what you are asking, and you shouldn't need more than a single measure to do it. Can you post a simple table of the IP addresses and the locations you want to see? (Don't try to chop the address into parts, that's just going to overcomplicate things.)
Gadgets Wiki GitHub More Gadgets...
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 no problems barging in

These are the IP Ranges that we use and I want to substitute the office location or Mobile Carrier

eg if IP starts with 172.16 or 172.18 then Id like to substitute with Mobile Carrier Connection or 192.168.41 is Leeds VPN Connection and 192.168.51 is Manchester VPN Connection

10.50.2.
10.50.3.
10.50.1.
10.36.70.
10.36.40.
10.36.20.
192.168.51.
192.168.41.
172.20.
172.30.
10.55.
172.16.
172.18.

Thanks

Martyn
User avatar
death.crafter
Posts: 1042
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, 12:46 pm Hi no problems barging in

These are the IP Ranges that we use and I want to substitute the office location or Mobile Carrier

eg if IP starts with 172.16 or 172.18 then Id like to substitute with Mobile Carrier Connection or 192.168.41 is Leeds VPN Connection and 192.168.51 is Manchester VPN Connection

10.50.2.
10.50.3.
10.50.1.
10.36.70.
10.36.40.
10.36.20.
192.168.51.
192.168.41.
172.20.
172.30.
10.55.
172.16.
172.18.

Thanks

Martyn
I am sorry but could you make it more clearer?

First of all, give full IP adresses and which part you would like to substitute.

Well, formatting them as,

[192.168.51].xxx

[172.16].xxx.xxx

[10.55].xxx.xxx

can help, these [parts] denote what you want to substitute, or what are your conditions. If you want them to be equal or in a range etc.
from the Realm of Death
My Current Desktop