How to know if a Port is available for my application I am going to Install - ports

I have a very doubt , plz correct me ..
I have a windows server and I need to install a application/product on it . This application/product uses certain ports, and I need to enter those ports while configuring this application.
So I need to know if say 19800 port is available or not.
what I did to know if 19800 is available or not:
1)netstat -na -- this gave me list of ports with status listening/established/Time_wait ..
I didnt find 19800 port in outout of netstat -na..
So does that mean 19800 port is not there and I need to ask window administrator team to open this port?
2)I think netstat -na gives the port which are in use or accepting some connections ..
It actually doesn't give you list of all the ports that the server have , because server generally have more than 60000 ports , and the output from netstat -na gives somewhere 100 entries..
3)what I dream is to know what all ports are there on this server , and if I find my port name I can assign that port to my application.
Thanks
rick

If you want to check, the availability of a PORT, you may use different approaches the simplest one in this case could be depending on your programming language you may do the following:
port_available = TRUE
try:
open(HOST,PORT)
exception PORT_NOT_AVAILABLE:
port_available = FALSE
Using the output from netstat and parsing it using text editor could be a nightmare.

Related

What port(s) can I use for a messenger application

Please forgive me for being naive on the subject, however, I do not understand ports and how they work in the slightest. I am trying to make a program where two computers could communicate given their IP addresses and I am using TCP protocol. I don't, however, know what port(s) I would be able to use for this application, because when I look up TCP ports I get a list of ports each with their own function. Any help is useful.
P.S. I am using C to create my program
The short answer is you can choose any port you like - although the safe range is generally considered to be between 1024 and 65535. The only problem that you will encounter is when some other program installed on the device is already listening on that port. Unfortunately, there is no port that is guaranteed to be available to listen on.
One possible solution to this is to have a primary listening port and a fallback secondary port. You can then first try to connect on the primary port and, if a satisfactory response is not received, try to connect on the secondary port. However, even this is not infallible, as there is a chance that the secondary post could also be in use.
The easiest approach is to try to create your listener on the port that you have chosen, and if the port fails to create, let the user know that some other application is preventing execution of your application.

What other non-default ports can i use for webserver?

I am using 80(http) and 443(https) default ports for my webserver.
What ther ports other than this can i use for my webserver.
I need this basically to start my webserver using non-default ports.
Any. Look at these for the ones to not use:
http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
You can use whatever ports you want to use, provided no other server on your box is also trying to use it.
This is, of course, subject to any OS-specific issues like needing to run with elevated privileges for binding to ports below 1024.
The IANA (naming authority) and ICANN (assigned names and numbers) is responsible for assigning ports to specific applications but there's nothing requiring you to follow those "rules" at all.
If you use (for example) port 23 for your HTTP server, that will work. It's likely to confuse any telnet programs attempting to connect to that box but, as stated, the box is under your jurisdiction, not that of the IANA. Provided your browsers hook up to the specific port 23, they'll work just fine.
By way of example, many IBM mainframe systems will use port 23 for their 3270-protocol terminal programs and bump "real" telnet up to port 1023.
And, in any case, why should you not use a port because it's "allocated" to the Quake game server, or Dropbox, or Symantec bloatware? :-)

Recommended port for proxy server

I'm trying to create a proxy server, and am having trouble decide on a trivial thing -- the port number on which it will listen. Is there some kind of convention on which port a proxy server should run on? Or should it just be greater than 1024?
Normally, you just pick a port and make it changeable for the user (or yourself). Simply, if it is already used on the system you run your proxy on, use a different one.
Many free proxy servers even listen (e.g. this) to default ports, like 8080. As long as the port is not in use on your system, it does not matter, as the real port is negotiated after a connection attempt.
For your interest, a list of registered ports can be found on the IANA (Internet Assigned Numbers Authority), which manages stuff like that. That is only a hint. I normaly use a random port like 8888 or so, even if someone somewhere already uses that.

How to find the port number of any PC?

Currently, I'm working on TCP client/server implementation in C. In that, I found that I can give any random number as a port number for my PC. Is it correct procedure? Or is there any standard port number for my PC?
I don't know the standard, but I say it's not. At least, I don't like to do it like that.
You can check occupied ports by parsing the outputs of programs like netstat and avoid using those. You can also use the method that attempts connecting on one port, and upon failure, tries another port. Unless you're really really unlucky, you should get a valid port on second try.
You should use ports within the ranges of 49152–65535. Ports below 49152 are reserved/registered.
Basically, you can use any port (given sufficient access rights). But server and client have to agree on the port, and it should not be already used by another application.
Hence, many ports are already reserved for special applications. 80 is for HTTP, 22 is for SSH and so on. The file /etc/services gives more detailed information.
Port numbers 0-1023 are called Well Known Ports, numbers 1024-49151 are called Registered Ports (not all of them are, but you get the idea).
If your question is whether you can give any port number to have your server listening to,
then you are thinking wrong, TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them, you can use non-privileged ports(ports > 1024). just make sure that any other application is not already using that port (above 1024) using netstat

Address already in use while executing C socket programme

Hii All,
While running a socket programme (server side ) am getting message like
Address already in use
Am trying to connect to port 80 since port 80 is reserved for https application So before running server side programme i am closing all application that uses https application ,is it enough...
or am doing it wrong??
Am trying to make a communication between browser and termial...
You must run your application as super user(root) on Linux or administrator privileges on Windows in order to bind to port 80. This is the case for all service ports, which is < 1024. Either that or there still is another program binded to that port.
Try using netstat to find out what programs might be listening on port 80.
Example:
on Linux:
netstat -punta
on Windows:
netstat -ban
Both must be run with super user/admin privileges in order to see the program names that bind to specific ports.
If you just closed another process listening on 80 port, this port will be blocked for a certain timespan depending on your OS. This behavior is here to prevent an attacker to crash a service on your machine and immediately restart a malicious service on the same port.
This behavior can be disabled by using SO_REUSEADDR (by using setsockopt).
If your main problem is to communicate from a custom server to your broswer, you can use any port in your server for providing HTTP (8080 is common for that), just specify the port in the url http://server:port/ (ie. http://localhost:8080/)

Resources