how do open port on firewall using java programmatically...


any upnp code ...

plz help me its urgent.........

:sigh: Is this suppossed to be some kind of crack program? In any case, there is no blanket answer to that anyway. It depends.

If it is a firewall on the machine, then it depends on the software. Are there CLI command that you can use? Then ProcessBuilder/Runtime.exec(). Is there an API? Then is there a Java library? If yes, then use that, if no, then is there a defined JNI Interface? If yes, use that. If no, write a JNI Interface.

Is the firewall on the router? If yes, is there an HTML access? If yes, use HttpURLConnection. If no, is there an SSH access? If yes, use JSch from JCraft. If no, is there a telnet access? If yes use Apache commons, if no, you will need to figure out how it is accessed otherwise.

In otherwords, you are, almost definately, in far over your head.

actually i developed client/server program using java socket with rmi...

when i contact server through client connection could not be created...

when i turn off windows firewall its fine...other than its not working...

its not cracking anything..

IOW, your application should not be worried about the firewall. That is a security issue. Configuring the firewall to open that port is the job of the administrators not your application. The only time a Java application should attempt to do anything with a firewall is when the application is meant to be the management software for that firewall.

IOW, don't turn off the firewall on your machine, configure it to open that port for outgoing/incoming traffic as applicable. If you do not know how to configure your firewall, then ask at a site related to the firewall in use as that is not a Java question.

ok u plz understand..


its not any intrude activity...


just i need to contact my server from client event it is behind firewall...

i don't like to switch off any thing...

So then don't switch anything off, as I said. Configure the firewall properly to allow traffic on the concerned port. It is not that hard to understand. If you insist on doing it from Java then see my first reply and choose the applicable method. If you don't know which method that is, then research your firewall software a bit and find it out.

i seen JSch from JCraft ...

it shows jhttptunneling...

this is my code...

public class Server {

	private ServerSocket serverSocket;
	
	private boolean enabled;
	
	private List<IServerListener> listeners = new LinkedList<IServerListener>();
	
	public void addServerListener(IServerListener listener) {
		listeners.add(listener);
	}

	public void removeServerListener(IServerListener listener) {
		listeners.remove(listener);
	}
	
	public void close() {
		enabled = false;
	}
	
	public void bind(int port, CallHandler callHandler) throws IOException {
		bind(port, callHandler, new DefaultFilter());
	}
	
	public void bind(final int port, final CallHandler callHandler, final IProtocolFilter filter) throws IOException {
		serverSocket = new ServerSocket();
		serverSocket.setPerformancePreferences(1, 0, 2);
		
		enabled = true;
		
		serverSocket.bind(new InetSocketAddress(port));
		String address=InetAdrUtility.getLocalAdr()+"";
		String[] strarr=address.split("/");
		final JHttpTunnelClient jhtc=new JHttpTunnelClient(strarr[1], port);
		//if(proxy_host!=null){
		  jhtc.setProxy(strarr[1], 8080);
	//	}

		// jhtc.setInBound(new InBoundURL());
		// jhtc.setOutBound(new OutBoundURL());
		jhtc.setInBound(new InBoundSocket());
		jhtc.setOutBound(new OutBoundSocket());

		jhtc.connect();
	        final InputStream jin=jhtc.getInputStream();
	        final OutputStream jout=jhtc.getOutputStream();
		
		Thread bindThread = new Thread(new Runnable() {
			public void run() {
				while (enabled) {
					Socket acceptSocket = null;
					try {
						acceptSocket = serverSocket.accept();
						
						final Socket clientSocket = acceptSocket;
						ConnectionHandler.createConnectionHandler(clientSocket,
								callHandler,
								filter,
								new IConnectionHandlerListener() {
							
							public void connectionClosed() {
								for (IServerListener listener : listeners)
									listener.clientDisconnected(clientSocket);
							}
							
						});
						for (IServerListener listener : listeners)
							listener.clientConnected(clientSocket);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}, String.format("Bind (%d)", port)); //$NON-NLS-1$ //$NON-NLS-2$
		bindThread.start();
	}
	
}

how do vahnge according to that...

we need to install any http proxy server separately....


plllllllzzzzzzzzzzz help me..........

That is not what I was suggesting. I never said (or even hinted) that you should attempt to use ssh tunneling. If you can't connect to the port with one protocol, you probably can't connect to it with another either, as you probably have the port completely blocked, and tunneling is not going to help with that. I suggested SSH if your firewall is on the router, not the local machine, and it provides an SSH access for configuring the firewall and you still insisted on your application configuring the firewall.

You have no idea what you are doing do you? Well, in order to anything about this you need to learn about firewalls in General, so go do a little studying and then come back to this question and you will, hopefully, realise how wrong this question is.

ok...

my firewall is in local machine...

u correct i have no idea and i don't know internals about firewall...

somebody suggest me to convert tcp port into http 80...

but its need application server ..i don't like broad my developemnt...

so i need simple proxy applicaion in java to intgerate with my existinf apps...

in my p2p apps i can traVerse NAT BY PORTFORWARDING...

BUT LOCAL FIREWALL IRRITATING ME.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.