简体   繁体   中英

How i can know if the IP host a sites or not by PHP (Reverse IP)

How i can know if the IP host a sites or not by PHP (Reverse IP) ?

For example :

This IP 62.75.138.253 host 5 sites www.earthwar.de , video-4u.com ..ect

If i have and IP i just need to know if it host a websites or not

I think gethostbyaddr is not useful here

Could anyone help please ?

How i can know if the IP host a domains or not by PHP ?

There is no single function for this: It's a non-trivial task. gethostbyaddr() will get you the one domain name that was configured to be the host name for the IP. That's about all you can get easily.

There are various companies on the web that collect domain names, resolve them, and store the information in a database. It is possible that there are paid services that offer you access to an API, but that doesn't seem to be what you have in mind.

I'm the creator of host.io , which shows 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 to your question. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM