Created
May 24, 2020 23:07
-
-
Save sonnyp/c952d64f32aa69d2010523ba6ff0c4b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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