I need to create a function in Google sheet to get my external (public) IP address
I tried use function =IMPORTXML("https://api.myip.com","//body"), but this method shows diffrint IP address not my external IP address
the reason the IP is different is because you are getting the IP of Google Sheets location not your IP
The following solution makes use of a custom menu in the Spreadsheets -
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('My Menu')
.addItem('Get IP', 'getIP')
.addToUi();
}
function getIP() {
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().appendRow([JSON.parse(UrlFetchApp.fetch('https://api6.ipify.org?format=json')).ip]);
}
You're free to modify the script to place said IP anywhere in the sheet, as required.
Also, I'm making use of the IPv6 address, as opposed to IPv4 but should you want to switch it to IPv4, replace the URL from the code to https://api.ipify.org?format=json - you may find this resource here.
I've asked out & around and this cannot (in any way) be achieved via a custom formulae, as such formulas run within a wrapper of sorts (that do not interact with any client-side elements). Hope this helps.
Edit note
Adding a way to insert external IP using custom menu to the specific cell (current cell, to be precise) -
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('My Menu')
.addItem('Get IP', 'getIP')
.addToUi();
}
function getIP() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var currentCell = sheet.getCurrentCell();
var ip = JSON.parse(UrlFetchApp.fetch('https://api6.ipify.org?format=json')).ip;
currentCell.setValue(ip)
}
By using this method, the IP would be added to the cell that has been selected.
You may wonder why current cell was chosen instead of active cell - well, the answer to that is because the document prefers us to do so :) I bet it would work even if we were to use active cell (haven't tested that though but I don't see a reason why it wouldn't)
It's not possible to use a Google Sheets custom function or Google Apps Script server side address to get you external IP because the related code is executed on the server side and Google Apps Script services doesn't include methods to get that but you could use client-side code to the get the external IP address. Additional, if it is required to send the IP address to an spreadsheet, the you could use do that by using google.script.run or the Google Sheets API.
NOTE: The closest Google Apps Script classes are Class Session and Class User.
Related
How to get client's IP address using JavaScript?
References
https://developers.google.com/apps-script/reference
Related
I am programmatically setting up a cluster resource (specifically, a Generic Service), using the Windows MI API (Microsoft.Management.Infrastructure).
I can add the service resource just fine. However, my service requires the "Use Network Name for computer name" checkbox to be checked (this is available in the Cluster Manager UI by looking at the Properties for the resource).
I can't figure out how to set this using the MI API. I have searched MSDN and multiple other resources for this without luck. Does anybody know if this is possible? Scripting with Powershell would be fine as well.
I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.
It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).
The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.
Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.
I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.
This is what the whole thing looks like (I ommitted the code for adding the resource):
using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))
{
// This query finds the newly created resource and fills in the
// private props we'll change. We have to do a manual WQL query
// because CimSession.GetInstance doesn't populate prop values.
var query =
"SELECT PrivateProperties FROM MSCluster_Resource WHERE Id=\"{YOUR-RES-GUID}\"";
// Lookup the resource. For some reason QueryInstances does not like
// the namespace in the regular form - it must be exactly like this
// for the call to work!
var res = session.QueryInstances(#"root/mscluster", "WQL", query).First();
// Add net name dependency so setting UseNetworkName works.
session.InvokeMethod(
res,
"AddDependency",
new CimMethodParametersCollection
{
CimMethodParameter.Create(
"Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
});
// Get private prop bag and set our props.
var privProps =
(CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
privProps.CimInstanceProperties["UseNetworkName"].Value = 1;
// Persist the changes.
session.ModifyInstance(#"\root\mscluster", res);
}
Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.
Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.
I am developing a Mozilla Thunderbird plug-in and need to get the user's email address.
Question: How do I retrieve this address?
I will use it inside a JavaScript.
You should first keep in mind that a user can have multiple e-mail addresses (from multiple accounts or even multiple identities for one account), and you have to decide in which one you are interested.
Note: there may exist an easier way then described below, e.g. a helper function in the existing Thunderbird Code. You could try to search comm-central for it
You somehow have to get the nsIMsgIdentity for the identity you are interested in. It has an email property, with the e-mail adress as a string.
One way to get all Identities should be via the allIdentities of nsIMsgAccountManager (didn't test it).
Use the follwing code to get the nsIMsgAccountManager:
Components.utils.import("resource:///modules/mailServices.js");
let accountManager = MailServices.accounts
If you have an nsIArray of nsIMsgIdentity, you can use the following code to loop over them:
for (let identity in fixIterator(identities, Components.interfaces.nsIMsgIdentity)) {
}
References which could be useful:
Overview of some interesting interfaces:
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_interfaces
Some account example Code:
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_examples
I need to make a Reverse Geocoding for my SD app with Genexus X Ev3 U7, to show a location through aa given address in the map within the app. I've struggled for some time figuring out how to make it work with no luck.
I've already read all the documentation, followed the steps to get the API key from google (with Geocoding and Geolocation APIs enabled) and tried different ways with the methods shown in it and i haven't made it work.
Should I consider something else? Does anyone have done this before?
thanks before hand
Yes, there are two methods in Geolocation external object: GetAddress() and GetLocation().
If you are using it on the client-side, then both Android and iOS implementations use the platform's native implementation.
If the code runs on the server-side (C# or Java), then the implementation uses Google's geocoding services. The problem here is that there is no way to provide an API Key, so the number of allowed requests by day may be too low (depending on your usage).
Well, the main problem was that i was capturing the values of the Address Domain Collection variable all wrong.
All i had to do was to declare an &Address variable that read an &Addresses collection variable and to give it to a &Adrs VarChar variable:
For &Address in &Addresses
&Adrs = &Address
Load
EndFor
where &Addresses = GeoLocationAPI.GetAddress(&GeoLocation)
I don't know how i didn't come up with this before.
Thanks everyone :)
I am using bing maps ajax control in a webapplication with a bing maps enterpise key.One of the modules include a functionality to geocode a list of addresses requested by the user.I am using the following code snippet to do the geocoding.
for (var i = 0, j = addresses.length; i < j; i++) {
searchManager.geocode({
where : addresses[i],/*<address>,<city>,<state>,<country>,<zip>*/
count : 5,
callback : success,
errorCallback : failure
});
};
The success% is very less.Close to 10% even after multiple tries(about 150 addresses to geocode).
So,I wanted to know if there is any way we can use the Address class(http://msdn.microsoft.com/en-us/library/hh868069.aspx) for geocoding instead of giving address as a string.The official documentation mentions only about giving address as a string(http://msdn.microsoft.com/en-us/library/hh868060.aspx). The reason I wanted to check with address class instead of string is because,with the bing maps SOAP api in a silverlight application,i had found the success% to be more while using Address class.
Thanks in advance for any help in this issue.
First off, if you have the address data somewhere you should geocode it ahead of time. Geocoding all your address in JavaScript with your map is slow and it also uses a lot of transactions thus making you run out of free usage fast. Is there a reason why you are geocoding addresses in a loop in a JavaScript app rather than geocoding a head of time?
It is often better to pass in the address as a single string and allow the geocoder to parse it. This is actually a tip the is used for the REST services as well when geocoding.
What is the most up to date, accurate, turn-key code to inject into a page to automatically read a user's IP and spit out their city... on this page we are borrowing from goingtorain.com I want it to display ... within 3 miles of (dynamic city)
http://www.drillavailable.neighborrow.com/
Another one we've been looking at to use is http://www.maxmind.com/app/geolitecity. Looks to be fairly simple to setup and is open source/free with apis for most popular languages.
Not done much other than play with it for 5 mins but looks promising.
I'd go with location aware browsing. Look into the W3C GeoLocation API.
For example, try Google Gears Geolocation module.
These technologies allow your clients to be geolocalized not only by looking and their IP (which can have 200km offsets) but also by triangulating SSID information from nearby wireless Access Points, and this can be extremely precise.
Once you have the (lon,lat) coordinates, it's just a matter of calling some webservice to get the nearest city's name.
I would choose the locator API at http://ipinfodb.com You can access it via XML or JSON, send it your API key and an IP and it will return the city, state, zip, country, etc. You can then parse the results in your language of choice. Its the simplest way to achieve this without actually storing any information about IP/location routing.
Yes, you only need to use the ClientLocation object in the google.loader namespace. In total the whole code is.
<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
alert(google.loader.ClientLocation.address.city);
} else {
alert("Not found");
}
</script>
The properties available are
google.loader.ClientLocation.latitude
google.loader.ClientLocation.longitude
google.loader.ClientLocation.address.city
google.loader.ClientLocation.address.country
google.loader.ClientLocation.address.country_code
google.loader.ClientLocation.address.region