From 2ecf9b8d31457175c6cc4ca5a441a165556afb77 Mon Sep 17 00:00:00 2001 From: RblSb Date: Wed, 19 Feb 2020 12:06:37 +0300 Subject: More buttons Emotes, filters, config, server history, autologin, tab blinking --- src/server/Utils.hx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/server/Utils.hx (limited to 'src/server/Utils.hx') diff --git a/src/server/Utils.hx b/src/server/Utils.hx new file mode 100644 index 0000000..c3510c9 --- /dev/null +++ b/src/server/Utils.hx @@ -0,0 +1,30 @@ +package server; + +import js.node.Http; +import js.node.Os; + +class Utils { + + public static function getGlobalIp(callback:(ip:String)->Void):Void { + Http.get("http://myexternalip.com/raw", r -> { + r.setEncoding("utf8"); + r.on("data", callback); + }); + } + + public static function getLocalIp():String { + final ifaces = Os.networkInterfaces(); + for (field in Reflect.fields(ifaces)) { + final type = Reflect.field(ifaces, field); + + for (ifname in Reflect.fields(type)) { + final iface = Reflect.field(type, ifname); + // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses + if ('IPv4' != iface.family || iface.internal != false) continue; + // this interface has only one ipv4 adress + return iface.address; + } + } + return "127.0.0.1"; + } +} -- cgit v1.2.3