IP address of domain on shared host

廉价感情. 提交于 2019-12-11 17:42:21

问题


I have domain on a shared hosting provider. How do I find the direct IP address of 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:


  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




回答2:


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.




回答3:


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!



来源:https://stackoverflow.com/questions/2924736/ip-address-of-domain-on-shared-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!