Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created August 13, 2020 11:02
Show Gist options
  • Save angelovstanton/f7ecf0ac02147ca16581403ca91f5fad to your computer and use it in GitHub Desktop.
Save angelovstanton/f7ecf0ac02147ca16581403ca91f5fad to your computer and use it in GitHub Desktop.
public void refreshTorIdentity(String userName) {
try (Socket socket = new Socket("127.0.0.1", 9151)) {
OutputStream output = socket.getOutputStream();
String authenticationCommand = String.format("AUTHENTICATE \"%s\"\r\n", userName);
output.write(authenticationCommand.getBytes());
output.write("SIGNAL NEWNYM\r\n".getBytes());
InputStream input = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
if (!line.contains("250")) {
System.out.println("Unable to signal new user to server.");
}
} catch (UnknownHostException ex) {
System.out.println("Server not found: " + ex.getMessage());
} catch (IOException ex) {
System.out.println("I/O error: " + ex.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment