Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


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,081 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,081 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,081 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,081 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
  • 17,661 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

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#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

    John

  • Active Members
  • PipPipPipPipPipPip
  • 13,108 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
 
 
OMG! Women are the cows of people.


#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
  • 17,661 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.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users