简体   繁体   English

如何在不写入主机文件的情况下将IP映射到python中的主机名

[英]How to Map an IP to hostname in python without writing in hosts file

I am using windows 7 and python 2.7 I created local https server with redirect url to server as its IP address. 我正在使用Windows 7和python 2.7,我创建了本地https服务器,并将重定向URL重定向到服务器作为其IP地址。 I created cert file for https using openssl. 我使用openssl为https创建了证书文件。 Then I mapped my local system IP(172.16.17.84) to myapp.nobies.in in hosts file of windows . 然后,我将本地系统IP(172.16.17.84)映射到Windows的hosts文件中的myapp.nobies.in So my server redirect url becomes https://myapp.nobies.in:443 . 因此,我的服务器重定向URL变为https://myapp.nobies.in:443 By doing this IP mapping in host file, I am not getting SSL error . 通过在主机文件中进行此IP映射, 我没有得到SSL错误 But, I want to distribute my app to others, so, writing in host file through python code is not desirable, as it needs administrative privileges. 但是,我想将我的应用程序分发给其他人,因此不希望通过python代码写入主机文件,因为它需要管理权限。 So, is there any way to assign/map this IP with hostname instead of making an entry in hosts file. 因此, 有什么方法可以用主机名分配/映射此IP,而不是在hosts文件中进行输入。

Have you considered just creating the certificate for the IP address? 您是否考虑过仅为IP地址创建证书? That wouldn't be much more fragile (probably less fragile, actually) than having to manually add the domain name to hosts files. 那将比必须手动将域名添加到主机文件要脆弱得多(实际上可能不那么脆弱)。 See https://stackoverflow.com/a/11710762/138772 and https://stackoverflow.com/a/8444863/372643 for more info on that. 有关更多信息,请参见https://stackoverflow.com/a/11710762/138772https://stackoverflow.com/a/8444863/372643

An alternative, but one probably requiring more work, would be to include a local DNS server in your app that redirects the domain name to your IP address. 一种替代方法(可能需要更多工作)是在您的应用程序中包含一个本地DNS服务器,该服务器将域名重定向到您的IP地址。 I can't really say what the best one to use for that would be, though. 不过,我真的不能说最好的选择是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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