From bd27d3137dae3831fd84abf784c9bb7782646876 Mon Sep 17 00:00:00 2001 From: Alexander Shulgin Date: Fri, 14 Jul 2017 06:38:14 -0600 Subject: [PATCH] update ip reporting --- pom.xml | 2 +- runtime/launch4j_windows.xml | 10 +++++----- .../java/com/wolandsoft/sss/pcr/Receiver.java | 16 ++++++++++++++-- .../com/wolandsoft/sss/pcr/server/TcpServer.java | 13 ++++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index e4f8114..785f88e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.wolandsoft.sss pc-receiver - 1.4.0.0 + 1.4.1.1 SssPcReceiver PC Receiver for Simple Secret Storage diff --git a/runtime/launch4j_windows.xml b/runtime/launch4j_windows.xml index 8857265..8f2c05e 100644 --- a/runtime/launch4j_windows.xml +++ b/runtime/launch4j_windows.xml @@ -2,7 +2,7 @@ true gui - pc-receiver-1.4.0.0.jar + pc-receiver-1.4.1.1.jar ..\target\SiestoPcReceiver.exe @@ -28,12 +28,12 @@ 64/32 - 1.4.0.0 - 1.4.0.0 + 1.4.1.1 + 1.4.1.1 Siesto PC-Receiver Wolandsoft (Alexander Shulgin) - 1.4.0.0 - 1.4.0.0 + 1.4.1.1 + 1.4.1.1 Siesto PC-Receiver Siesto PC-Receiver diff --git a/src/main/java/com/wolandsoft/sss/pcr/Receiver.java b/src/main/java/com/wolandsoft/sss/pcr/Receiver.java index 488b859..8594c25 100644 --- a/src/main/java/com/wolandsoft/sss/pcr/Receiver.java +++ b/src/main/java/com/wolandsoft/sss/pcr/Receiver.java @@ -21,9 +21,15 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Base64; +import java.util.Collections; +import java.util.Enumeration; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.CRC32; @@ -44,6 +50,7 @@ import com.wolandsoft.sss.pcr.ui.TrayIconUI.TrayIconListener; public class Receiver implements TrayIconListener, ServerDataListener { + private static final int PROTOCOL_VER = 1; private static final Logger logger = Logger.getLogger(Receiver.class.getName()); public static void main(String[] args) throws InterruptedException { @@ -89,14 +96,18 @@ private void hideQRCode() { @Override public void onShowKey() { hideQRCode(); - + try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); + // store IP + byte[] host = mServer.getIP(); + dos.writeInt(host.length); + dos.write(host, 0, host.length); // store port dos.writeInt(mServer.getPort()); //store host - byte[] host = mServer.getHost().getBytes(StandardCharsets.UTF_8); + host = mServer.getHost().getBytes(StandardCharsets.UTF_8); dos.writeInt(host.length); dos.write(host, 0, host.length); // store key @@ -109,6 +120,7 @@ public void onShowKey() { checksum.update(payload, 0, payload.length); long checksumValue = checksum.getValue(); baos.reset(); + dos.writeInt(PROTOCOL_VER); dos.writeLong(checksumValue); dos.writeInt(payload.length); dos.write(payload); diff --git a/src/main/java/com/wolandsoft/sss/pcr/server/TcpServer.java b/src/main/java/com/wolandsoft/sss/pcr/server/TcpServer.java index c52deeb..e038d4e 100644 --- a/src/main/java/com/wolandsoft/sss/pcr/server/TcpServer.java +++ b/src/main/java/com/wolandsoft/sss/pcr/server/TcpServer.java @@ -18,10 +18,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.DatagramSocket; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.net.UnknownHostException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; @@ -67,7 +69,7 @@ public void run() { logger.log(Level.WARNING, e.getMessage(), e); } byte[] data = baOutStream.toByteArray(); - if(data.length > 0) { + if (data.length > 0) { mListener.onDataReceived(data); } } @@ -89,6 +91,15 @@ public int getPort() { return mPort; } + public byte[] getIP() { + try (final DatagramSocket socket = new DatagramSocket()) { + socket.connect(InetAddress.getByName("8.8.8.8"), 10002); + return socket.getLocalAddress().getAddress(); + } catch (UnknownHostException | SocketException ignore) { + return mLocalAddress.getAddress(); + } + } + public String getHost() { return mLocalAddress.getHostName(); }