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?
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?
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('getIp');
}
<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>
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.
The following code will return user's ip:
getIp.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p id="ip"></p>
<script type="text/javascript">
var userip;
</script>
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
<script type="text/javascript">
document.write("Your IP is :", userip);
</script>
</body>
</html>
Code.js
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('getIp');
}