• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a client lie about its IP address to the server using Java?  RSS feed

 
Ranyodh Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to set the user agent property to other than Java/1.4.2_02, and also send requests to the server that should appear coming from ip specified by me. In another words i am trying that I could hit the server with variety of different setting of user-agent and ip address. I have this piece of code that works fine for the user-agent. But how can I send request to the server mimicking different ip addresses. Any ideas?thanks

I don't to download the page. I just have to send the requests.

Here is the code that sends different user-agent configurations to the server:



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.text.html.HTMLDocument;

public class teste {

private static HttpURLConnection conn = null;
private static URL url = null;
private static HTMLDocument html = new HTMLDocument();

public static void main(String args[]) {
BufferedReader in = null;
String str = "";

try {
url = new URL("http://www.google.com/search?hl=de&ie=ISO-8859-1&q=test");
} catch(MalformedURLException e) {
System.out.println(e);
System.exit(-1);
}

try {
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040803");
conn.connect();
in = new BufferedReader(new InputStreamReader(url.openStream()));

} catch(IOException e) {
System.out.println(e);
System.exit(-1);
}

}

}

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To spoof the IP address, you need lower-level access to the IP stack than Java gives you. I don't think this is possible using Java networking.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to mention that, even if you did spoof the IP address, the server would try to respond to the spoofed address and would fail without the client ever hearing back.
 
Ranyodh Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying...

Actually, I don't need to get reply from the server, i just have to send the request and I don't care about getting reply. I just have to register a hit to the server.

So, Do i have any way now..

I also think that I may not able to it with Java.

I have also though another way. I can place a proxy server in between that will send fake ip addresses.
And i will send my request to the proxy server through java. Is it possible.

I have link that contains a code to send a request to the proxy server.
Have a look at it: http://bdn.borland.com/article/0,1410,29783,00.html

So, what do u think of it. Or please tell me ANY other way.
Thanks Using URLConnection to connect to the proxy server
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!