runnign through a proxy

import jav.net.*;

import java.io.*;

import java.util.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

publicclass inetextends JFrameimplements ActionListener

{

public JButton ok;

public JTextField host, ip;

public JPanel prim;

public JLabel ho, i;

public inet()

{

ok =new JButton("find ip");

host =new JTextField(15);

ip =new JTextField(15);

ho =new JLabel("host");

i =new JLabel("ip address");

ip.setEditable(false);

prim =new JPanel();

ok.addActionListener(this);

prim.add(ho);

prim.add(host);

prim.add(ok);

prim.add(i);

prim.add(ip);

}

public JPanel getPrim()

{

return prim;

}

publicvoid actionPerformed(ActionEvent e)

{

if(e.getSource() == ok)

{

try

{

String add = host.getText();

get(add);

}

catch(IOException io)

{

JOptionPane.showMessageDialog(null,"error");

}

}

}

publicvoid get(String a)throws IOException

{

try

{

InetAddress remote = InetAddress.getByName(a);

//System.out.println(remote.getHostName());

//System.out.println(remote.getHostAddress());

ip.setText(remote.getHostAddress());

}

catch(UnknownHostException uhe)

{

JOptionPane.showMessageDialog(null,"could not find host");

}

}

}

as you an see, I have written a very simple program to find the ip of the host specefied.

I am trying to expand my knowlage of programming with net and io, and I came accross the question. What If I wanted to run this app on a machine that runs through a local proxy server.

My question to you is this. Is there a way to impliment the InetAddress commands to run through a local proxy, or maybe another class I could impliment to achieve this goal.

thanks in advance for any and all help.

[3887 byte] By [xpyro_666xa] at [2007-11-27 6:47:06]
# 1

There are several ways to use a proxy in network communications over sockets. But I don't know whether they help you force getByName() or such methods to communicate through a proxy.

You can set a proxy for entire networking in Java by adding some key/value pairs to system properties:

System.getProperties().put(損roxySet?攖rue?;

System.getProperties().put(損roxyPort?攑ort?;

System.getProperties().put(損roxyHost?攈ost?;

Where "port" and "host" values are the proxy port and the proxy address respectively.

Arash.Shahkara at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 2
You have to set the following System propertieshttp.proxyHost (default: <none>)http.proxyPortSee http://www.rgagnon.com/javadetails/java-0085.html for an example.Bye.
RealHowToa at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 3

No, that will have no effect on the DNS requests, or any other requests except HTTP.

@OP: DNS requests don't go through a proxy server in any circumstances. They always go via your local DNS system, and it knows where to go next for requests it can't answer itself. The proxy server doesn't come into it at all. If your DNS system isn't working correctly you should talk to your netadmin. There is nothing you need to do about it in Java.

ejpa at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 4

Well in this case that I am in need of implimentation.

the proxy is the one making the dns requests.

the network runs so that only a select few computers are directly wired to the net, and the computers we use are wired to access the net through them.

Ie. (localhost -> network proxy -> internet)

xpyro_666xa at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 5
> You can set a proxy for entire networking in Java by> adding some key/value pairs to system properties:By 'entire networking' I hope you mean just HTTP.> System.getProperties().put(損roxySet?攖rue?;This does nothing. Try setting it to 'false'!
ejpa at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 6
> the proxy is the one making the dns requests.InetAddress remote = InetAddress.getByName(a);Here your code is the one making a DNS request.
ejpa at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...
# 7
Thanks ejp
Arash.Shahkara at 2007-7-12 18:19:39 > top of Java-index,Core,Core APIs...