so I made a php script that returns the IP Address of the user, And when i open it on my browser it returns an IPV6 IP Address (If the user has IPV6 or it will return IPV4).
But when I make a URLConnection to the same link using Java, It outputs a IPV4.
This is the code I am using in my java application along with the URL to my website.
String ip = new JSONObject(new BufferedReader(new InputStreamReader(LynxClient.getConnection(new URL("https://lynxclient.com/getip.php")).getInputStream())).readLine()).getString("ip");
System.out.println(ip);
public static HttpsURLConnection getConnection(URL url) throws IOException {
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mozilla/4.76");
conn.setUseCaches(false);
return conn;
}
and here is my PHP Code for my website.
<?php
$ip = null;
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
echo json_encode(array('ip' => $ip));
So my issue is the browser and my java application returns wrong IP Address, which I want both of them to be the same, I am not sure what is wrong here, I have checked some threads made on SO regarding this but none has helped me so far.