Skip to content

Instantly share code, notes, and snippets.

@sonnyp
Created May 24, 2020 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonnyp/c952d64f32aa69d2010523ba6ff0c4b6 to your computer and use it in GitHub Desktop.
Save sonnyp/c952d64f32aa69d2010523ba6ff0c4b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env gjs
const { GLib, GUPnP } = imports.gi;
const { MainLoop } = GLib;
const mainloop = new MainLoop(null, true);
function getExternalIpAddress() {
// does it work with interface: null or without
const context = new GUPnP.Context({ port: 0, interface: "enp0s31f6" });
context.init(null); // needed?
const controlPoint = new GUPnP.ControlPoint({
client: context,
//
target: "urn:schemas-upnp-org:service:WANIPConnection:2",
});
controlPoint.connect("service-proxy-available", (self, serviceProxy) => {
log("service proxy available");
const [success, NewExternalIPAddress] = serviceProxy.send_action_list(
// action
"GetExternalIPAddress",
// in_name
[],
// in_values
[],
// out_names
["NewExternalIPAddress"],
// out_types
[imports.gi.GObject.TYPE_STRING],
);
log(success);
log(NewExternalIPAddress);
});
controlPoint.set_active(true);
}
getExternalIpAddress();
mainloop.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment