共享主机上域的IP地址

发布于 2024-09-03 09:47:11 字数 100 浏览 2 评论 0原文

我在共享托管提供商上拥有域名。如何使用 Python 查找我的域的直接 IP 地址?

是否可以使用 IP 地址而不是网站本身发布到我的域上的脚本?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月无声 2024-09-10 09:47:11
  1. 我猜IP应该是静态的,所以你真的需要多次查找它吗?

  2. 您需要指定域名,以便网络服务器知道要使用哪个主机配置(如果您没有专用 IP 或您的主机是该网络服务器的默认主机)

  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

紧拥背影 2024-09-10 09:47:11
import socket
socket.gethostbyname("www.stackoverflow.com")
'69.59.196.211'

将为您提供域的 IP 地址(作为字符串)。

但是,如果它是共享主机,我认为您不太可能通过 IP 访问您的主机 - 很可能您会拥有类似 Apache 的 VirtualHost 指令 限制您只能“看到”对您的域的请求。对 IP 地址的请求将由某些默认配置提供服务。

很大程度上取决于您托管的性质。

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.

以歌曲疗慰 2024-09-10 09:47:11

一个奇怪的请求...

要查找域名,请执行以下操作:

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

关于发布到 IP 地址:
我认为它不会以正常方式工作(例如通过浏览器),因为该地址下可能有许多网站。

但是,我想如果您将客户端套接字连接到站点的 IP 地址,但仍然在 HTTP 主机请求标头中发送网站名称,那么您可以使用编程语言(例如 Python)以非常手动的方式完成此操作。

我不知道这是否提出的问题多于它所回答的问题,我也不知道你为什么要执行上述任一操作,但事实就是如此。

祝你好运!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文