Jump to content



Photo

IP Lookup and Concatenate


  • Please log in to reply
15 replies to this topic

#1 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 01 June 2012 - 05:28 PM

Hello,

I'm very new to this but I love it so far. I've written a couple of really basic programs but I need to do a more complex one and I'm having some trouble with how it will work.

What I'd like to do is have the program look up the local IP Address and add that number with the last octet changed to 55 and save that to a variable.

Is this possible or does anyone have any directions I can look in?

Thanks in advance, this stuff is rad.







#2 UEZ

UEZ

    Never say never

  • MVPs
  • 5,328 posts

Posted 01 June 2012 - 05:34 PM

Can you give an example what you mean?

Br,
UEZ
 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

#3 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 01 June 2012 - 05:39 PM

Yes,

What I want to do is have the program look up the IP address of the machine and save to a var. So lets say the IP of the machine is 10.XXX.XXX.XXX, the next step is to have the program change the last number of this series to 55 so it would read 10.XXX.XXX.55.

Does that make sense?

#4 armoros

armoros

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 01 June 2012 - 06:02 PM

Sorry to ask but why to do that ?

#5 UEZ

UEZ

    Never say never

  • MVPs
  • 5,328 posts

Posted 01 June 2012 - 06:03 PM

Something like that?

$ip = @IPAddress1 $new = StringRegExpReplace($ip, "(d{1,3}.d{1,3}.d{1,3}.)d{1,3}", "${1}55") MsgBox(0, "Test", "New IP: "& $new)


Br,
UEZ
 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

#6 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 01 June 2012 - 06:49 PM

Hmmm, I'll need to look into that StringRegExpReplace.

This will be used to add network printers at different locations.

Thanks for your help UEZ, I'm pretty psyched about using this.

#7 UEZ

UEZ

    Never say never

  • MVPs
  • 5,328 posts

Posted 01 June 2012 - 07:16 PM

Here another way:

$ip = @IPAddress1 $new = StringLeft($ip, StringInStr($ip, ".", 0, -1)) & "55" MsgBox(0, "Test", "New IP: "& $new)


Br,
UEZ
 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

#8 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 01 June 2012 - 08:05 PM

Your addition is working perfectly but DOS is telling me "INVALID PARAMETER", I'll keep plugging away.

How did you find these things you are showing me?

#9 UEZ

UEZ

    Never say never

  • MVPs
  • 5,328 posts

Posted 01 June 2012 - 08:08 PM

Your addition is working perfectly but DOS is telling me "INVALID PARAMETER", I'll keep plugging away.

How did you find these things you are showing me?


Practical knowledge. ;)

Br,
UEZ
 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

#10 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 01 June 2012 - 08:16 PM

So the MVP title is well earned. Hopefully I can get up to speed to be able to make these types of things.


Thanks again for your help ;)

#11 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 18,153 posts

Posted 01 June 2012 - 09:17 PM

I know UEZ has answered your question, but here's another SRE.

Local $sIPAddress = @IPAddress1 Local $sReturn = StringRegExpReplace($sIPAddress, '((d{1,3}.){3})d{1,3}', '${1}55') MsgBox(4096, '', $sReturn & @CRLF)


Edit: Also just to show that there are more ways to achieve the same goal here is using the native AutoIt functions (though UEZ's is way more efficient! Hint: he doesn't use StringLen, therefore one less function call.)
Local $sIPAddress = @IPAddress1 Local $sReturn = StringTrimRight($sIPAddress, StringLen($sIPAddress) - StringInStr($sIPAddress, ".", 0, -1)) & "55" MsgBox(4096, '', $sReturn & @CRLF)

Edited by guinness, 01 June 2012 - 09:36 PM.

  • Robonglious likes this
UDF List:
Spoiler
Updated: 31/03/2015

#12 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 04 June 2012 - 03:41 PM

I don't fully understand how StringInStr is working. It doesn't make sense how it takes off the last octet. I see that the string is declared and the substring is "." but it seems like this would subtract 3 each time which is incorrect.

I'm sure I just don't understand how this is working.

Thanks for your help

#13 JohnOne

JohnOne

    Number #1

  • Active Members
  • PipPipPipPipPipPip
  • 14,336 posts

Posted 04 June 2012 - 04:04 PM

StringLen() is telling the length of the whole string
StringInStr() is telling the position of the last "."

So StringLen() - StringInStr() gives the number of chars to trim from the right.
Then concat 55
  • Robonglious likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    

 

Monkey's are, like, natures humans.


#14 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 04 June 2012 - 04:42 PM

Great solutions, thanks everyone!

#15 Robonglious

Robonglious

    Seeker

  • Active Members
  • 23 posts

Posted 04 June 2012 - 04:53 PM

aha!:AutoIt Absolute Beginners

#16 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 18,153 posts

Posted 04 June 2012 - 09:57 PM

Thanks JohnOne. I should've explained it in my post really, but wasn't think at the time.

Edited by guinness, 04 June 2012 - 09:59 PM.

UDF List:
Spoiler
Updated: 31/03/2015




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users