开发者

IP address of domain on shared host

I have domain on a shared hosting provider. How do I find the direct IP address o开发者_运维技巧f my domain using Python?

Is it possible to post to a script on my domain using the IP address and not the website itself?

Thanks.


  1. I guess the IP should be static so do you really need to look it up more than once?

  2. You need to specify the domain name so that the webserver knows which host configuration to use if you don't have a dedicated IP or your host is the default for that webserver


import socket
socket.gethostbyname("www.stackoverflow.com")
'69.59.196.211'

will get you the ip address (as a string) of your domain.

However, if it's shared hosting I would think it highly unlikely that you'll be able to access your hosting via the ip - most likely you'll have something like Apache's VirtualHost Directive in place which limits you to only 'seeing' requests to your domain. Requests to the IP address will be served by some default configuration.

Would very much depend on the nature of your hosting.


A curious request ...

To look up a domain name, do something like this:

import socket
ipaddress = socket.gethostbyname('www.bbc.co.uk')

Regarding posting to the IP address: I don't think it would work in the normal way (like from a browser), because there will probably be many sites held under that address.

But, I guess you could do it in a very manual way, using a programming language (e.g. Python), if you connected a client socket to the site's IP address, but still sent the website's name in the HTTP Host request header.

I don't know if that poses more questions than it answers, and I don't know why you'd want to do either of the above, but there it is.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜