Powershell Script to get list of primary domain and IP address

Hi, I need a script which can get the top-level domain and URL which has IP address.

I have a text file with following url

https://domain.gh.com/url/url/site/flash.sw
https://domain.com/url/url/site/flash.sw

https://192.168.1.100/url/url/site/flash.sw
http://192.168.5.5/url/url/site/ufalt.html

After putting the file through a script the list should look like this

://gh.com
://
domain.com

https://192.168.1.100/
http://192.168.5.5/

What have you tried? Do you have any code to start? I’m not aware of a script that would do this already (maybe try powershell gallery).

If you are trying to tackle this from scratch I would probably start by manipulating each string to split it up in its relevant parts i.e. -split “:” and -split “//” and -split “.”

Post back with some code, and I’ll do my best to help.

lol this is grep/regex
Assume you have a file named waffles.txt with:

https://domain.gh.com/url/url/site/flash.sw
https://domain.com/url/url/site/flash.sw

https://192.168.1.100/url/url/site/flash.sw
http://192.168.5.5/url/url/site/ufalt.html

grep -E -o “([0-9]{1,3}[.]){3}[0-9]{1,3}” waffles.txt
^This gets you the IPs

grep -Eo “[a-zA-Z0-9]+([-.]?[a-zA-Z0-9]+)*.[a-zA-Z]+” ./fox.txt
Is super messy but would get you domain names.

You just need to learn regex/grep and as Mike said split things between // and the following /

Good luck and have fun :wink: