Guest User

Untitled

a guest
Jun 25th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
  2.  
  3. import java.net.Authenticator;
  4. import java.net.PasswordAuthentication;
  5.  
  6. public class ProxyAuthenticator extends Authenticator{
  7.  
  8. private String userName, password;
  9.  
  10. protected PasswordAuthentication getPasswordAuthentication(){
  11. return new PasswordAuthentication(userName,password.toCharArray());
  12. }
  13.  
  14. public ProxyAuthenticator(String userName, String password){
  15. this.userName = userName;
  16. this.password = password;
  17. }
  18.  
  19. //and my proxy configuration with sample code
  20.  
  21. public static void main(String args[]) throws IOException, InterruptedException {
  22.  
  23. Authenticator.setDefault(new ProxyAuthenticator("myUserName@somemail.com", "mySecretPassword"));
  24. System.setProperty("https.proxyHost", "VPNServerHostname");
  25. System.setProperty("https.proxyPort", "VPNServerPort");
  26.  
  27. Document doc = Jsoup.connect("https://tools.keycdn.com/geo" )
  28. .timeout(30000)
  29. .userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")
  30. .get();
  31.  
  32. String ip = doc.select("th:contains(IP) + td").text();
  33. String isp = doc.select("th:contains(Hostname) + td").text();
  34. String provider = doc.select("th:contains(Provider) + td").text();
  35. String country = doc.select("th:contains(Country) + td").text();
  36.  
  37.  
  38. System.out.println("IP: " + ip + "nHostname: " + isp + "nProvider: " + provider + "nContry: " + country + "n############################################"+"n");
  39.  
  40. }
Add Comment
Please, Sign In to add comment