从Google Web App检索公共IP [英] Retrieve Public IP From Google Web App
问题描述
Google脚本文档没有描述以任何方式从作为Web应用程序发布的Google Apps脚本中检索客户端的IP地址。
可以这样做吗?
/ p>
客户端访问已发布的Web应用程序是通过Google的代理服务器提供的,因此,任何获取客户端IP的尝试都会报告代理服务器的IP 。
没有提供客户端IP的Service API,但我们可以通过HTML服务使用外部JavaScript库。
以下是一些演示代码,从如何获取客户端的IP地址只使用javascript?
Code.gs
function doGet(e){
return HtmlService.createHtmlOutputFromFile('getIp');
}
getIp.html
< script type =application / javascript>
函数getip(json){
alert(json.ip); //提醒IP地址
}
< / script>
< script type =application / javascriptsrc =http://jsonip.appspot.com/?callback=getip>< / script>
结果
在一次测试中,警报弹出 216.191.234.70
。查找该IP:
绝对不是我的IP地址。
结论:用户使用Google Script的公共IP地址。
The Google Scripts documentation does not describe any way to retrieve the client's IP address from a Google Apps Script published as a Web App.
Can that be done?
Client access to published Web Apps is channeled through Google's Proxies, so any attempt to get a client's IP will instead report the proxy's IP.
There are no Service APIs that provide a client's IP, but we can use external javascript libraries through the HTML service.
Here is some demonstration code adapted from How to get client's IP address using javascript only?
Code.gs
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('getIp');
}
getIp.html
<script type="application/javascript">
function getip(json){
alert(json.ip); // alerts the ip address
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
Result
In one test, the alert popped up with 216.191.234.70
. Lookup of that IP:
That's definitely not my IP address.
Conclusion: No, you can't retrieve a user's public IP address using Google Script.
这篇关于从Google Web App检索公共IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!