Sign in to follow this  
Followers 0

IP Lookup and Concatenate

16 posts in this topic

#1 ·  Posted

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Can you give an example what you mean?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

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

Share this post


Link to post
Share on other sites

#3 ·  Posted

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?

Share this post


Link to post
Share on other sites

#4 ·  Posted

Sorry to ask but why to do that ?


[font="verdana, geneva, sans-serif"] [/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted

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


Please don't send me any personal message and ask for support! I will not reply!

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

Share this post


Link to post
Share on other sites

#6 ·  Posted

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted

Here another way:

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

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

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

Share this post


Link to post
Share on other sites

#8 ·  Posted

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?

Share this post


Link to post
Share on other sites

#9 ·  Posted

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


Please don't send me any personal message and ask for support! I will not reply!

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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 ;)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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
1 person likes this

UDF List:

 

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

 

 

Updated: 02/04/2015

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

Share this post


Link to post
Share on other sites

#13 ·  Posted

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

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#14 ·  Posted

Great solutions, thanks everyone!

Share this post


Link to post
Share on other sites

#15 ·  Posted

aha!:

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Edited by guinness

UDF List:

 

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

 

 

Updated: 02/04/2015

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