# Powershell Script to get list of primary domain and IP address

**URL:** <https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241>\
**Category:** PowerShell Help\
**Created:** [November 17, 2020, 4:38am UTC](https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241 "2020-11-17T04:38:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalajee](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@lalajee](https://forums.powershell.org/u/lalajee)\
**Post date:** [November 17, 2020, 4:38am UTC](https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241/1 "2020-11-17T04:38:31Z")

</div>

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.gh.com/url/url/site/flash.sw)  
[https://domain.com/url/url/site/flash.sw](https://domain.com/url/url/site/flash.sw)

[https://192.168.1.100/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](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](http://gh.com)  
 ://_[domain.com](http://domain.com)

[https://192.168.1.100/](https://192.168.1.100/)  
[http://192.168.5.5/](http://192.168.5.5/)

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [November 17, 2020, 4:49am UTC](https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241/2 "2020-11-17T04:49:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ciphers](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@ciphers](https://forums.powershell.org/u/ciphers)\
**Post date:** [November 18, 2020, 3:52pm UTC](https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241/3 "2020-11-18T15:52:55Z")

</div>

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.gh.com/url/url/site/flash.sw)  
[https://domain.com/url/url/site/flash.sw](https://domain.com/url/url/site/flash.sw)

[https://192.168.1.100/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](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 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/powershell-script-to-get-list-of-primary-domain-and-ip-address/15241/4 "2024-05-16T20:28:20Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


