Last active
September 2, 2016 12:59
-
-
Save LeonanCarvalho/5a891ad4b028eb7a28da92e68de8e75b to your computer and use it in GitHub Desktop.
This file contains 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
import java.io.BufferedReader; | |
import java.io.DataOutputStream; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import javax.servlet.http.HttpServletRequest; | |
//... | |
private HttpServletRequest request; | |
// Your class here (...) | |
public String getUserIP(){ | |
//Top L2jBrasil use only trusth real IP | |
String proxyIp = request.getHeader("X-FORWARDED-FOR"); | |
String cloudFlareIP = request.getHeader("CF_CONNECTING_IP"); | |
if(cloudFlareIP != null){ | |
return cloudFlareIP; | |
} | |
if (ipAddress != null) { | |
return ipAddress; | |
} | |
return request.getRemoteAddr(); | |
} | |
public boolean validateVote(String Ip) throws Exception { | |
String UserName = "yourusername"; | |
String url = "http://top.l2jbrasil.com/votesystem/?ip="+ getUserIP() + "&username="+UserName; | |
String userAgent = request.getHeader("User-Agent"); | |
URL obj = new URL(url); | |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); | |
con.setRequestMethod("GET"); | |
//add request header | |
con.setRequestProperty("User-Agent", userAgent);//L2jBrasil Only Accept a valid user agente, so clone the user useragent | |
int responseCode = con.getResponseCode(); | |
if(responseCode == 200){ | |
BufferedReader in = new BufferedReader( | |
new InputStreamReader(con.getInputStream())); | |
String inputLine; | |
StringBuffer response = new StringBuffer(); | |
while ((inputLine = in.readLine()) != null) { | |
response.append(inputLine); | |
} | |
in.close(); | |
//print result | |
System.out.println(response.toString()); | |
}else{ | |
System.out.println("\nSending 'GET' request to URL : " + url); | |
System.out.println("Response Code : " + responseCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment