Skip to content
Snippets Groups Projects
Commit 25273f7c authored by Guy Zana's avatar Guy Zana
Browse files

java: add new test that perform external TCP communication

requires starting qemu with tap networking, first install libvirt
then launch the run script as root with the -n option.

Example:

$ sudo ./scripts/run.py -d -n

in osv you'll have to configure networking as follows:

$ ifconfig virtio-net0 192.168.122.100 netmask 255.255.255.0 up
$ route add default gw 192.168.122.1
parent 880cf57a
No related branches found
No related tags found
No related merge requests found
package com.cloudius.cli.tests;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
public class TCPExternalCommunication implements Test {
@Override
public boolean run() {
try {
System.out.println("[~] connecting to 173.194.70.113...");
Socket s = new Socket(InetAddress.getByName("173.194.70.113"), 80);
s.setSoTimeout(2000);
BufferedReader in = new BufferedReader(
new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
System.out.println("[~] Client: writing message...");
out.write("GET / HTTP/1.0\r\n\r\n");
out.flush();
System.out.println("[~] Client: reading response...");
char[] buf = new char[512];
in.read(buf);
System.out.println("[~] Client: message received:");
System.out.println(buf);
System.out.println("[~] Client: closing connection");
out.close();
in.close();
s.close();
return (true);
} catch (Exception ex) {
System.out.println("[-] Exception in TCPEchoClient!");
System.out.println(ex.getMessage());
ex.printStackTrace();
return (false);
}
}
}
\ No newline at end of file
......@@ -65,6 +65,7 @@ public class TestRunner extends ScriptableObject {
@JSFunction
public void registerAllTests() {
this.register("TCPEchoServerTest", new TCPEchoServerTest());
this.register("TCPExternalCommunication", new TCPExternalCommunication());
this.registerELFTests();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment