Sign in to follow this  
Followers 0
d2038

Match the first part of a variable??

10 posts in this topic

Hello, i need a little help, im using this code to get my public ip and make it a variable:

#include <Inet.au3>
Do
    $1=_GetIP()
    Until $1<>
MsgBox(0, "", "It works")

Lets say that the ip is 142.13.76.245, what i want is to match only the 142.13 part, so when in the script it differs from this range, the msgbox pops up. Hope u can help me. Sorry for bad english.

Cheers.

Share this post


Link to post
Share on other sites



Hello, i need a little help, im using this code to get my public ip and make it a variable:

#include <Inet.au3>
Do
    $1=_GetIP()
    Until $1<>
MsgBox(0, "", "It works")

Lets say that the ip is 142.13.76.245, what i want is to match only the 142.13 part, so when in the script it differs from this range, the msgbox pops up. Hope u can help me. Sorry for bad english.

Cheers.

Get the location of the second "." with StringInStr(), then use that for StringLeft():
$sIP = "123.45.67.89"
$sIPSlash16 = StringLeft($sIP, StringInStr($sIP, ".", 0, 2) - 1)
ConsoleWrite("IP address /16 network = " & $sIPSlash16 & @LF)

You do it more geeky with StringRegExp(), but I suspect you don't want to go there yet...

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

d2038,

First, welcome to the Autoit forums.

I would deal with your problem this way:

; 142.13.76.245, what i want is to match only the 142.13 part

$nBegin = TimerInit()

While 1
    
    $1 = "142.13.76.245" ; You would put GetIP() here
    ; If match then exit the While...WEnd loop
    If StringInStr($1, "142.13.") Then ExitLoop
    ; Check for timeout
    If TimerDiff($nBegin) > 10000 Then ; This is set for 10 secs - you alter it to what you want
        MsgBox(0, "", "Timed Out")
        Exit ; This exits, you might want to do something else
    EndIf
    
WEnd

MsgBox(0, "", "It works")

The StringInStr line checks if the IP contains what you want and if so continues with the rest of the script. The Timer* parts check if a timeout period has elapsed (we do not want to do this all night, do we! :D ) and exits. Try altering the IP number to see the effect.

Ask if anything is unclear.

M23

Edit: Ah, beaten by a rakishly good looking waterfowl :D .

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ty both for ur help, problem solved, StringInStr() and StringLeft() were the functions that i needed, these will help me in the future xD, back to testing and finishing my script, cheers.

Share this post


Link to post
Share on other sites

Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run.

It's the last line where the bug is introduced. It should be (that last line that is):

MsgBox(64, "Title expressing exhilaration", "       I match!                ")

This is crucial.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run.

It's the last line where the bug is introduced. It should be (that last line that is):

MsgBox(64, "Title expressing exhilaration", "       I match!                ")

This is crucial.

Which is it today -- too much drugs coffee, or too little?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Which is it today -- too much drugs coffee, or too little?

:D

May I paraphrase (somebody, something, somewhere) and say: The shit I provided was meant to be a little over the top and therefore mildly humorous, but nobody ever seems to find the same things funny that I do...

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run.

It's the last line where the bug is introduced. It should be (that last line that is):

MsgBox(64, "Title expressing exhilaration", "       I match!                ")

This is crucial.

The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial  :D

Share this post


Link to post
Share on other sites

The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial  :D

So we could write this:

$sIP = "142.13.67.89"

If StringLeft($sIP, 7) = "142.13." Then
    MsgBox(64, "Title expressing exhilaration", "   AndyG says I match!                ")
EndIf

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial  :D

Just to keep in the spirit of things:

MsgBox(64, "Title expressing sorrow", "M23 apologises profusely")

:D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0