PDA

View Full Version : Parsing an IP address and manipulating it.....


mwreyf1
08-26-2005, 09:14 PM
I am using AMS5 and am trying to create an application to automate a printer setup using an HP print Server. Problem is that in order to make it work I need to be able to take an IP address (DHCP) and make a few changes and re-assemble the IP address and import changes to the registry.

Example:

10.175.55.123 being the IP addy of the system the app would be running on.

I need to take that IP and change the last oct (123) to (142). Then take the second oct (175) and subtract 64 which would give me (111) and then re-assemble that info into new IP 10.111.55.142. This is just an example of one location where this would be ran. The 2nd, 3rd and 4th octs will change from location to location.

I have tried every string function and stilll not having any luck.

I would GREATLY appreciate it if one of you guru's could point me in the right direction.

Thanks in Advance

Worm
08-26-2005, 11:11 PM
function DelimitedStringToTable(DelimitedString, Delimiter)
tbReturn = {};
local strWorking;
local nPos = nil;
local strData;
local nTableIndex = 1;
local nDelimiterLength = String.Length(Delimiter);

if(nDelimiterLength < 1)then
tbReturn[nTableIndex] = DelimitedString;
return tbReturn;
end

strWorking = DelimitedString;
nPos = String.Find(strWorking,Delimiter);
while(nPos ~= -1)do
strData = String.Left(strWorking,nPos-1);
tbReturn[nTableIndex] = strData;
nTableIndex = nTableIndex + 1;
local nLength = String.Length(strWorking);
strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
nPos = String.Find(strWorking,Delimiter);
end
if(strWorking ~= "")then
tbReturn[nTableIndex] = strWorking;
end

return tbReturn;
end

sIPAddress = "10.175.55.123"
tblOctets = DelimitedStringToTable(sIPAddress, ".")
tblOctets[4] = 142
tblOctets[2] = String.ToNumber(tblOctets[2]) - 64

sNewIPAddress = Table.Concat(tblOctets, ".")
Dialog.Message("IP Address", sNewIPAddress)

mwreyf1
08-27-2005, 08:22 PM
Thanks, Worm!

I tried your code and it works flawlessly.