1
我使用的Django ipware用於獲取用戶的公網IPDjango的給我本地IP總是在我的網站
https://github.com/un33k/django-ipware
我的網站託管在通過虛擬機djnago , mod_wsgi , apache
這是我的代碼
g = GeoIP()
ip_address = get_ip_address_from_request(self.request)
raise Exception(ip_address)
它給了我127.0.0.1
我正在通過同一網絡上的其他計算機訪問它。
我怎樣才能讓我的公網IP
我也試過這個問題,以及
PRIVATE_IPS_PREFIX = ('10.', '172.', '192.',)
def get_client_ip(request):
"""get the client ip from the request
"""
remote_address = request.META.get('REMOTE_ADDR')
# set the default value of the ip to be the REMOTE_ADDR if available
# else None
ip = remote_address
# try to get the first non-proxy ip (not a private ip) from the
# HTTP_X_FORWARDED_FOR
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
proxies = x_forwarded_for.split(',')
# remove the private ips from the beginning
while (len(proxies) > 0 and
proxies[0].startswith(PRIVATE_IPS_PREFIX)):
proxies.pop(0)
# take the first ip which is not a private one (of a proxy)
if len(proxies) > 0:
ip = proxies[0]
return ip
這回我192.168.0.10
我的本地計算機的IP
1.閱讀這個 [問題] [1] 2. VM的讀取文檔 [1]:http://stackoverflow.com/questions/4581789/我怎麼做,我用戶的IP地址在Django –
@AlokTiwari我已經閱讀該帖子,我從那篇文章中得到了我的解決方案。但找不到解決方案 – user1958218
您不會在您的局域網上獲取您的公共IP,因爲它永遠不會通過該接口進行代理。 – DivinusVox