Skip to content

Commit

Permalink
update ip reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs20 committed Jul 14, 2017
1 parent 623b564 commit bd27d31
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.wolandsoft.sss</groupId>
<artifactId>pc-receiver</artifactId>
<version>1.4.0.0</version>
<version>1.4.1.1</version>
<name>SssPcReceiver</name>
<description>PC Receiver for Simple Secret Storage</description>
<dependencies>
Expand Down
10 changes: 5 additions & 5 deletions runtime/launch4j_windows.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<launch4jConfig>
<dontWrapJar>true</dontWrapJar>
<headerType>gui</headerType>
<jar>pc-receiver-1.4.0.0.jar</jar>
<jar>pc-receiver-1.4.1.1.jar</jar>
<outfile>..\target\SiestoPcReceiver.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
Expand All @@ -28,12 +28,12 @@
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.4.0.0</fileVersion>
<txtFileVersion>1.4.0.0</txtFileVersion>
<fileVersion>1.4.1.1</fileVersion>
<txtFileVersion>1.4.1.1</txtFileVersion>
<fileDescription>Siesto PC-Receiver</fileDescription>
<copyright>Wolandsoft (Alexander Shulgin)</copyright>
<productVersion>1.4.0.0</productVersion>
<txtProductVersion>1.4.0.0</txtProductVersion>
<productVersion>1.4.1.1</productVersion>
<txtProductVersion>1.4.1.1</txtProductVersion>
<productName>Siesto PC-Receiver</productName>
<companyName></companyName>
<internalName>Siesto PC-Receiver</internalName>
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/wolandsoft/sss/pcr/Receiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/wolandsoft/sss/pcr/server/TcpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
}
Expand Down

0 comments on commit bd27d31

Please sign in to comment.