How to verify if port is open - java

Could anyone please help me with steps how to verify if port is open/available to use.
Basically we have to verify in one of our server (windows) that
7200 port is open for use.
we have one deployment coming up, and team have end point like htts://servername::7200/index.html

If you are trying to use TCP(Transmission Control Protocol) port then run the telnet host port and see the result
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access

Related

JVisualVM remote working when destination is behind NAT?

I am in developer network and the JBoss to be monitored using JVisualVM is behind client firewall in separate network. JBoss is exposed to us through a NAT. The exposed JMX port works when using telnet from our developer network, but JVisualVM still doesn't find the remote JMX. Apparently this can be due to two things: 1) one or several dynamic RMI sockets need to be accessed, or 2) the "java.rmi.server.hostname" is not defined. My problem may be both points 1 and 2, but apparently since we have SSH access this can be tackled according to this site:
http://rafaelsteil.com/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/
“java.rmi.server.hostname” is the public hostname (like example.com) of your server, without HTTP or anything else. You cannot use an internal address, otherwise you won’t be able to remotely access the service.
However I have one question about the "java.rmi.server.hostname", should the defined IP address be the server internal IP or NAT IP which is publicly expoed to our developer network?
I have actually just tackled this problem myself and figured it out.
I would wager that the problem is the RMI connections - you can't predict which ports it will use and so you can't get it to work with a firewall.
The workaround is to use an SSH proxy:
SSH to the box where your application is running but use the -D option like this:
ssh user#remoteHost -D 9999
This will start a socks proxy on your local machine on port 9999.
Open JVisualVM and in the preferences, under 'network' configure it to use a socks proxy at localhost, on port 9999.
If you do the above, you should then be able to connect to the remote machine as normal and since all the RMI traffic is now going over the SSH proxy, it is punched through the firewall and works nicely.
Good luck :-)

Stop server in eclipse project

I am developing a client server application in eclipse where the client and server connect through port 4444 to send numbers to eachother. However I am getting this error message
Address already in use: JVM_Bind
Does this mean that the port is in use? Can anyone advise me on how to fix this error?
Only one ServerSocket can bind a SocketAddress (IP address and port number).
Possible reasons why the address is already bound:
Another application on your system currently uses this port (in this case: pick another port)
You may still have a running instance of your application in the background (in this case: terminate it in the console view in Eclipse)
You attempted to bind the SocketAddress twice (in this case: fix your program).
I believe port 4444 is blocked on some routers by default. Running the command netstat -a in cmd should give you a list of all ports in use. Try using a different port if possible.

Java apps can't connect to IP, but I can ping it

I have a play application connecting to a database at 1.2.3.4 but for some reason Play! (and other java apps too) cannot connect to it.
I did try editing the hosts file and setting a name for the IP like app01 1.2.3.4 however it only worked on the box where the DB was hosted and it didn't work for external machines. I can confirm that the right port is open in iptables and I've tried restarting it, too.
If I ping postgres at port 4567 at 1.2.3.4 from the same box, it works. But setting the same IP address in my java apps fail. What's wrong? Is it permissions or iptables issue? Thanks.
Stack trace:
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:206)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
... 35 more
Can you connect to your DB via pgadmin (http://www.pgadmin.org/)?
Can you telnet from your machine on to the DB Server on the given port (telnet 1.2.3.4 4567)?
If you cannot telnet maybe the DB Server is blocking your connections?
Have you set any proxy server either only for java or only for rest of the system?
From the exception it seems more of a networking issue than anything with java...
Can you check firewall settings on the db server. You can try by telnet to check whether you are able to connect or not.
If you're behind a router you WILL BE ABLE to ping it from another local machine (usin the local IP), but you might not be able to ping from the outside if you are not port-forwarding correctly (You can configure this from your router).
Another thing to take in mind is that you CAN'T ping your own external IP from within the network, that means that you can ping 192.168.1.100 (Server) from 192.168.1.xx (Client), but you can't ping 72.15.xx.xx (port-forwarded to 192.168.1.100) from 192.168.1.xx (Client).
In order to do this you have to use an external tool, there are many webs that can do this for you, here's the one that I use:
http://www.yougetsignal.com/tools/open-ports/
If it says the port is open then it is open and it should work now, if it shows closed then you should double check that your firewall is allowing the data, maybe shut it down temporary to see it thats the prob.
If you need help adding a port exception to your firewall or forwarding a port from your router just tell me which distro/routerModel you're using and I'll try to dig some more info for you.

java tcp connection with public i.p

I am trying to tcp connect to a server machine in java, by using its public i.p. but when i run the client application i constantly getting a connection refused error. if i used localhost instead of the public ip, it works perfectly.
i search the internet for several causes of the issue but i couldnt fix it.
i forwarded the port to my machines' local i.p address(192.168.1.3) in routers settings. then i checked if port is listening when i ran the server application using netstat -an. i saw lines like,
0.0.0.0:19999 or []:19999 .
19999 is the port number i am trying to listen to. Then i changed my ServerSocket constructor to the 3 parameter one, which also binds the local address.
InetAddress miad = InetAddress.getByAddress(addr);
ServerSocket socket1 = new ServerSocket(port,10,miad);
addr is the InetAddress of my machines local i.p. After these modifications, when i start the server application, i run netstat and it shows:
TCP 192.168.1.3:19999 0.0.0.0 LISTENING
Here i think that my server is listening on the port specified properly.
I have also disabled my firewall and antivirus software.
I have seen several threads and discussions on the net about the issue, and tried most of the things mentioned there, but i keep getting the connection refused error.
What can i be doing wrong? It runs without any errors when i test with localhost.
This is because of the router (not very sure, but almost). Try to see if a webservice like www.canyouseeme.org can connect to your server.
The main idea is that an internal machine (inside the LAN) cannot connect to a machine inside the same LAN by using the external (public) IP address.
I'm pretty sure that it will work, using you internal ip (192.168.1.3).
And if you are sure that you forwarded ports correctly, CanYouSeeMe will say your server is reachable. If it doesn't, make sure you ISP isn't blocking the ports for some kind of "safety reasons".
To figure out if your problem relates to Java and programming please do
telnet 192.168.1.3 19999
If it can't connect then superuser.com would be a better place to discuss this issue.

Java Server Client Program I/O Exception

I made this program:
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
And it works perfectly if I put the server's hostname as 127.0.0.1 or my computers name (Ajay-PC).
However these 2 methods are LAN or local only not internet. So I changed it to my internet ip. 70.128.xxx.xxx etc. But it didn't work. I checked:
canyouseeme.org
and it said 4444 was CLOSED.
So I did a quick port forward.
Portforward:
Name: My Java Program
Start Port: 4444
End Port: 4444
Server IP: 10.0.0.12 <-- (Yeah this is my Local IP I checked)
then I tried
canyouseeme.org
AGAIN:
and it said 4444 was OPEN
I ran my server client program and it yet to work.
So my problem is the client server program is not working on the internet just locally. So something is blocking it and I don't know what.
EDIT: It's not blocked because as I checked the port is open. But I am recieveing a IO exception not a UnknownHost
Computer:
Windows Vista x64
Norton AntiVirus 2010
Thanks! I'll give best answer or whatever to who ever answers the best ;) :)
How do you have access to the internet? Maybe you have to configure your ADSL modem or your router/switch to forward the port 4444 to your computer.
I guess you are in the LAN if you are using a router connecting to your modem. And your computer connect to the router.
Try to connect to your modem which has your internet IP.
Have you checked that the client is connecting to port 4444 and your public IP? This is another common mistake most people make. If your port is open as you say above and the firewall is off, then there's nothing stopping you connecting.
Use Wireshark or WinDump to snoop the initial TCP handshake. Filter for packets with port 4444. Verify that the opening SYN packet is leaving your computer, that the opening SYN packet is returning to your computer, and to see what whether/how computer is responding to the opening SYN packet.
Note: if you experiment with these tools, you won't be able to use it trace if you use the localhost (127.0.0.1) and your PC IP (10.0.0.12) addresses - in these cases, the packets don't actually leave the computer and can't be snooped. Put the client and server on separate computers if you want to snoop packets on the LAN without involving the gateway.

Categories

Resources