#1 07 Jul 2016 18:55

cgman
Member
Registered: 16 Feb 2009
Posts: 47

IP address exclude

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

#2 08 Jul 2016 09:12

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: IP address exclude

Are you wedded to Powershell for this task?

Offline

#3 08 Jul 2016 13:13

cgman
Member
Registered: 16 Feb 2009
Posts: 47

Re: IP address exclude

I am.  The rest of my script is powershell, so it only makes sense to continue to use it.

Offline

#4 09 Jul 2016 02:18

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: IP address exclude

cgman wrote:

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

#5 11 Jul 2016 21:38

cgman
Member
Registered: 16 Feb 2009
Posts: 47

Re: IP address exclude

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

#6 12 Jul 2016 13:54

cgman
Member
Registered: 16 Feb 2009
Posts: 47

Re: IP address exclude

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

Board footer

Powered by FluxBB