Created
August 13, 2020 11:02
-
-
Save angelovstanton/f7ecf0ac02147ca16581403ca91f5fad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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