Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a few questions, please help:

Fist, I can access Google search just by typing http://74.125.224.211, because this is the IP address returned by nslookup.

However, I could not do so with the IP addresses returned from www.yahoo.com. How do I go to the Yahoo search page by its IP?

Another example, http://www.allaboutcircuits.com will resolve to 68.233.243.63 by DNS server, but if I go to http://68.233.243.63, I get "Hello world!".

Second, for some reason, there is something wrong with DNS resolvers with my web hosting service (it will not be fixed !!). So commands like

get_file_contents("http://www.allaboutcircuits.com");

will return php_network_getaddresses: getaddrinfo failed: Name or service not known

How do I get around this with IP address,

68.233.243.63

I mean, somehow attach the HTTP hostname parameter to get_file_contents()?

I would like to solve this on my own side (in my code), no troubleshooting/adjustment will be done by the server admin.

share|improve this question

migrated from stackoverflow.com Sep 14 '12 at 23:35

This question came from our site for professional and enthusiast programmers.

9  
Read about virtual servers and how a single host is able to host many websites. –  wallyk Sep 14 '12 at 23:30
    
I assume there's some reason you can't just use the domain name? –  Isaac Rabinovitch Sep 15 '12 at 3:09
    
@Isaac Rabinovitch: user1502776 says "there is something wrong with DNS resolvers with my web hosting service (it will not be fixed !!)" and "I would like to solve this on my own side (in my code), no troubleshooting/adjustment will be done by server admin." –  Bavi_H Sep 15 '12 at 3:51
3  
If your server admin is that stupid, you need to go find a different web hosting provider. –  Michael Hampton Sep 15 '12 at 7:30
add comment

5 Answers

In your PHP script, when you access it by IP address, you also need to send a Host: header in your request with the correct domain name.

This question on Stack Overflow explains how to do it: http://stackoverflow.com/questions/356705/how-to-send-a-header-using-a-http-request-through-a-curl-call

share|improve this answer
add comment

As wallyk said, it is virtual servers

Take this example for apache

<VirtualHost *:80>
ServerName example2.com
DocumentRoot C:/www/example2.com
</VirtualHost>

<VirtualHost *:80>
ServerName example.com
DocumentRoot C:/www/example.com
</VirtualHost>

In c:\www\example.com make an index file saying "Hello World! example.com"

in c:\www\example2.com make an index file saying "Hellow World! example2.com"

And change your hosts file to

127.0.0.1 example.com
127.0.0.1 example2.com

Then go to http://example.com then go to http://example2.com

So that is how you can have multiple sites per single ip

So basically the answer is, no you won't be able to get that site from the ip.

share|improve this answer
    
I get the point which is IP alone isn't enough. But is there any PHP command that uses IP and hostname which I provide to fetch remote webpages? The command should not query DNS. –  user1502776 Sep 15 '12 at 0:14
4  
While this may be technically accurate, it does not address the question. The question is asking how to request a specific site with a known hostname from a server with a known IP, without automatically resolving the IP address through DNS, using a PHP script. It is not asking how to find a hostname corresponding to a given IP. wallyk's comment is more relevant, because his link includes information on the Host header necessary for a server to distinguish between the websites it hosts and serve the correct one. –  Bob Sep 15 '12 at 2:19
add comment

You say you want to manually specify both the the host name and the IP address, instead of relying on a DNS server outside of your control. Looking at the comments at the file_get_contents documentation, I see commenters there have solved similar problems by creating a context that contains the needed Host: header. Something like this:

$context = stream_context_create(array('http' => array('header' => 'Host: www.allaboutcircuits.com')));
$data = file_get_contents('http://68.233.243.63/', 0, $context);

Of course, be aware that the disadvantage to manually specifying both the host name and the IP address is that if the IP address changes in the future (for example, if the site moves to a new hosting provider), your code could stop working until you manually update the IP address.

share|improve this answer
add comment

The IP address alone isn't enough to uniquely identify which site you want to go to when multiple virtual hosts are running on the same port/server. In that case, you need to specify the Host header in the HTTP request that identifies the server name. You can do this directly via telnet to port 80:

$ telnet 68.233.243.63 80
Trying 68.233.243.63...
Connected to 68.233.243.63.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.allaboutcircuits.com

where you type the telnet command, and the GET and Host lines, and then get the HTML source code returned from the server.

Or you can use curl where you specifically add the header (with the -H flag).

curl 68.233.243.63 -H "Host: www.allaboutcircuits.com"
share|improve this answer
add comment

Second, for some reason, there is something wrong with DNS resolvers with my web hosting service (it will not be fixed !!)

You could use another DNS server on the client side, in case it’s not the web host—8.8.8.8 and 8.8.8.6 are run by Google, and 4.4.4.2 is a common standby. Namebench will let you find the fastest. Alternatively, you could use a proxy service of some sort (I run my own on a VPS, or use Tor, but there are other options).

Since this is PHP, an even easier option would be to run the code on another system. Kludges aren't maintainable.

share|improve this answer
    
sounds like he's on some shared host, and can't modify DNS, which is why he has the caveat "I would like to solve this on my own side (in my code), no troubleshooting/adjustment will be done by server admin." I don't think he can modify the DNS . . . –  ernie Sep 15 '12 at 0:13
1  
He can use an alternate dns server on the client side to test. If his web host isn't setting up vhosts properly, he needs another web host. –  Journeyman Geek Sep 15 '12 at 1:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.