I'm the creator of host.io, which does something similar, showing you a list of all of the domains hosted on the same IP address (along with a list of domains that link to the domain, and more). For example, here's a list of domains hosted on the same IP as stackoverflow.com: https://host.io/stackoverflow.com
As you've discovered, getting the IP address for a single domain is only a very small part of the solution. There is no single command or script you can write to do this - you need to build out your own database of domains to IP address.
First need to get (or create) a list of all available domain names. There are roughly 250 million currently. The next step is to resolve all of those domains to an IP address. You then need to store all of those domain to IP pairs in a database, and then you can query to get a list of all domains on the same IP. And then you need to do that at a regular frequency to make sure it stays up to date.
To give a full example, let's create a file with 4 domains and resolve them to IP addresses:
$ cat domains.txt
facebook.com
fb.com
stackoverflow.com
stackexchange.com
# Let's resolve the domains to IPs with dig - could use nslookup or similar
$ cat domains.txt | xargs -I% bash -c "dig +short % | tail -n1" > ips.txt
31.13.76.68
31.13.76.68
151.101.129.69
151.101.193.69
# Let's combine the domains and IPs using paste
$ paste domains.txt ips.txt > combined.tsv
$ cat combined.tsv
facebook.com 31.13.76.68
fb.com 31.13.76.68
stackoverflow.com 151.101.129.69
stackexchange.com 151.101.129.69
# Let's create a DB table and import the data, and write a query
# to find any domains in our dataset that are hosted on the same
# domain as stackoverflow.com
$ psql $DB_URL
=> create table details (domain text, ip text);
=> \copy details from ~/combined.tsv;
=> select domain from details where ip = (select ip from details where domain = 'stackoverflow.com');
domain
-------------------
stackoverflow.com
stackexchange.com
(2 rows)
That's how you could build your own, or you could let someone else do the hard work, and use their data. We're one such provider, but others exist, like yougetsignal and domaintools.