You are not logged in.
Pages: 1
Hi,
I am trying to parse through multiple text files and extract the Ip address from each file and then save/append to a new file.
This is working with one caveat. I also need to exclude all ips from x.x.x.0-x.x.x.10 and .255. I have entertained the use of regex, but it is completely greek to me and do not know how to match on the last octet with the numbers that i mentioned previously. I am looking for some guidance to see if there is another way to efficiently parse the same IPs, exclude those mentioned and append to another file is the same Foreach and IF loop.
Thanks,
cgman
Offline
Are you wedded to Powershell for this task?
Offline
I am. The rest of my script is powershell, so it only makes sense to continue to use it.
Offline
I also need to exclude all ips from x.x.x.0-x.x.x.10 and .255. I have entertained the use of regex, but it is completely greek to me and do not know how to match on the last octet with the numbers that i mentioned
A simple regexp is not so good in this case but a few simple regexp can help
If the data is a regular list of IP addresses then these will match a single digit from 0 to 9, then only 10 and only 255 on the end, and you'd use them to exclude these from the list.
.*\.[0-9]
.*\.10
.*\.255
Last edited by foxidrive (09 Jul 2016 02:18)
Offline
So far this works except for all ips starting with .2-.10 using "split" answer from here:
http://stackoverflow.com/questions/3006 … egex-split
$string.GetAddressBytes())[3] -join "."
If ($LastOctet -lt "10") {do this}
should this work?
thx
Offline
This seems to have fixed my issue
$string.GetAddressBytes())[3] -join "." -as [int]
not sure why it worked for a few number, but all seems well at the moment.
Thanks for your help
cgman
Offline
Pages: 1