getting the port number of a website - java

How can i obtain the port number of a website using a program. Is there any method / way that i can use to know the port number of a website ?
Or, if i know that my port number 52970 is connected with 212.58.241.131 this ip , can i know the port number with which the port number of my PC is connected ?

I believe you need to review the concept of port numbers.
By default, HTTP uses port 80. So an individual website you visit won't need access to any other port.
TCP and UDP port numbers

I am not sure what you are looking for but from a PHP script you can get the port the client uses to connect to your web server with $_SERVER["REMOTE_PORT"]

The port number for http is port 80 and 443 for ssl.
If you are on windows start up cmd and type netstat -a -b to see what program connects where.
Please elaborate or post an example of what you want to achieve as it's not quite clear to me.
€dit: in php you can find the remote or server port with
$_SERVER['REMOTE_PORT']
or
$_SERVER['SERVER_PORT']
If I am right, you are looking for the remote port.
http://php.net/manual/en/reserved.variables.server.php
for telnet look here :
http://www.geckotribe.com/php-telnet/

I am not sure if this helps you at all but the gold standard for scanning ports has to be nmap.
http://nmap.org/
You can scan open ports for a specific IP address.

echo $_SERVER['SERVER_PORT']."<br/>";
echo $_SERVER['REMOTE_PORT']."<br/>";
'SERVER_PORT'
The port on the server machine being used by the web server for
communication. For default setups, this will be '80'; using SSL, for
instance, will change this to whatever your defined secure HTTP port
is.
'REMOTE_PORT'
The port being used on the user's machine to communicate with the web
server.

Related

Client-Server Chat application JAVA

I have a simple java written client and server chat application(with sockets). When running on the same network/computer it works fine. However when i try to run the client from a different network it doesn't connect. I tried using the public IP address of the server to connect the client to the server but without luck. How would I be able to connect to the server app from a different network? any help would be appreciated.
It sounds like you have more of a firewall issue than a problem with the application. Instead of trying to connect with the Java client, first try connecting with Telnet to the server from the same computer, then from the other computer. The first effort will show you what to expect when it works. For instance, if your server is running on port 999, use telnet server.example.com 999.
If the machines are Linux boxes, use iptables -L to see whether there is a block on the port you are trying to access.
If you're still having problems reaching the server, run tcpdump -i tcp:999 on the server host to see what traffic is making it to your server socket, then run the telnet commands again. You should see the tcp connection established when connecting from the local machine, maybe or maybe not when connecting from other machines. If you don't see it while connecting from other machines, run tcpdump there too to make sure the client is definitely sending the traffic to the server.
After you are sure that the server can receive traffic and that your client is sending the traffic, there are no mysteries about what is actually going on and you should find your problem.
It worked after I did port forwarding on router. Most of the ISP provided modem/routers wont let you manipulate ports so had to buy my own modem/router, forwarded the port and worked like a charm. Information on what port forwarding is can be found here : http://www.howtogeek.com/66214/how-to-forward-ports-on-your-router/

Java Server and Client work local but not over ip

I wrote a Simple Java Server-Client program. It works all fine when I use "localhost" as address in the Socket's constructor, but it fails when I specify my actual IP. Thus I think the problem is not in the Java-code.
I've forwarded the Ports on my Router (a Speedport w921v from the German provider Telekom). On Windows 7 I've turned down every Firewall. I tried as well on Ubuntu 14. I use really the correct ip and not a local ip like 127. or 192.. When typing sudo netstat -tulpe I find this record which might belong to my program
tcp 0 0 *:10300 *:* LISTEN
10300 was the port I gave the Server with server = new ServerSocket(10300);
When I try to communicate with the port via telnet xx.xxx.xx.xxx 10300 I can't get no response but if I type telnet localhost 10300 I will get an answer.
I have really no clue why this problem occurs.
Sorry for the bad English ;)
Use the ServerSocket() constructor and bind() to the particular IP and port you wish to use. Your machine may be multihoned and your Java server program may listen only to a particular network address, even if you didn't specify an actual address.

Incoming connection on port 80 to webserver application

I made a Java web application running on tomcat, what I'm trying to do now is letting people outside my net acceding my application.
I've read lot of guides and I understood I need to forward incoming traffic on port 80 to the raspberry hosting it (listening on port 8080).
What I did was going to the router panel and make a port forwarding with the following parameters:
Are all the parameters right?
What should i put in the remote IP address?
What I meant to do is redirecting request on port 80 to local port 8080 on which the raspberry is listening (if tomcat is listening to port 8080 if i write something like ip/webappname will I access my application?)
By the way, with the following settings, if I write my "outside" ip as url, I get prompted with a user\password form. I tried to make some tcpdump to try to understand if it's raspberry or router related, but I got tons of packets and couldn't find a way out, what could it be? Thanks.

Java, gaming, and port forwarding

I created a Battleship game in Java to work with Sockets and ServerSockets. The game works fine on LAN, but I would like to be able to play against someone on a completely different network. I understand port forwarding would be necessary, but would I have to forward the port on every client that is playing the game? Or would it only be necessary to forward the port on the router the server is using? Thanks.
Port forwarding is only required on the server. Any packets bound for the client will be auto-forwarded from the initial request thanks to the action on many NATs.
So, you only need to forward the port on the server. If using Socket and ServerSocket you need to forward TCP if your router gives you the choice. If using DatagramSockets, forward UDP at either of the endpoints.
(if you had to forward on clients, you most likely wouldn't have been reading this page without forwarding port 80)
To elaborate on what #hexafraction is saying, here's what you can do:
Build a server that any client can connect to. Clients can generally connect to anything they want. Firewalls usually place restrictions on information that can flow in, but not flow out. So if the clients know the server to connect to, they can connect to it without modifying their firewall and then the server will coordinate transferring the data between the clients.
I did this and all I had to do was forward the port I was using in my router to my local I.P. address. If you don't know your local ip address run a command prompt (assuming your using windows ) and run ipconfig to figure it out. If your at home using a wireless router access it by browser to 192.168.1.1 Hope this helps!

which port to use for applet servlet communication

I am trying to communicate between an applet and a servlet. I first tried Http connection. But I am not getting the desired result. Hence decided to switch to socket communication. Hence I wanted to know which port to use for the same. I remember reading somewhere that port 80 is ideal. Is it port 80 or port 8080? I need a port that is not blocked by firewall(default).
By default, an Applet can only connect to the same host as the applet was served from. You can't set up TCP connections arbitrary hosts. (see e.g. here for info on how to sign an applet, signed applets does not have this restriction)
Using port 80 likely will not work either, as your web server probably works on port 80. Port 80 is really the only port that you usually can count not being blocked, if your servlet container is running on port 8080 , port 80 might be free for you to use though.
imo, try rather to communicate with http so you can talk to a servlet - and work out whatever desired results you had trouble with.

Categories