How to find out which ports are used by a program?

6

4

I try to figure out which ports a specific program uses if they send data to the internet. Is there a tool which is able to find this out? Or do I have to do package inspection by using wireshark?

Background: I try to create a priority rule on my fritz!box 7490 router, so that some computer games are seen as real-time applications and there are as less lags as possible e.g. if someone in the network decides to watch videos on youtube while I am playing online.

Black

Posted 2017-03-25T17:19:51.050

Reputation: 3 900

You do know in most cases opening a port for a program isn't required unless you explicitly closed the port. Most consumer routers don't do that. – Ramhound – 2017-03-25T17:26:41.493

I have to specify the port range which my computer game uses so that I can select that game for the priority rule. Thats why I need to know the ports. – Black – 2017-03-25T17:28:41.350

Netstat should provide you which ports are being used. Will have to use detective reasoning to figure it out though. Wireshark can also be used. Most documented programs also list which poets are used – Ramhound – 2017-03-25T17:32:49.643

Google "name of the game" port forwarding. You will find out which ports you need to open exactly. They are common ports for engines used by games, so its not really that hard to figure out. – LPChip – 2017-03-25T17:39:21.063

2Also, opening secondary ports will not improve your lag. Once a port is open, it remains open, and lag happens DURING the game, not at the start. – LPChip – 2017-03-25T17:40:02.123

Programs can also open random ports as they are running ... – DavidPostill – 2017-03-25T17:40:54.367

I do not try to port forward. I try to setup QoS... I already figured out the port by using wireshark. It says Destination Port 27022 – Black – 2017-03-25T18:01:12.560

Answers

9

  1. Determine PID of your program

    tasklist | find "myprogram.exe"
    
  2. Check ports in third column of output from

    netstat /a /n /o | find " 4564"
    
    • there is a space before PID to rule out inappropriate matches potentially coming from other columns (a little trick)
    • /n keeps addresses in numeric form (without resolving) what causes the command to finish without delays (it should suffice for what you need)

miroxlav

Posted 2017-03-25T17:19:51.050

Reputation: 9 376

Or you can use the /b flag to netstat to list the names of the executables right there. However, note that it will only list executables you have permission for (unless you run it as admin). – Moshe Katz – 2017-03-27T22:01:13.277

@MosheKatz - /b flag was not suitable for this case because of use of simple filtering using find. If someone wants to browse through full listing or use some advanced row filtering technique, then they can go with /b, but otherwise /o is much more convenient. – miroxlav – 2017-03-28T08:34:05.973

I have one question left: netstat showed that GTA5.exe uses UDP Ports 6672, 17185 and 52164. Why is rockstar not mentioning 17185 and 52164? And why they say that we also need UDP Ports 61455, 61457, 61456 and 61458 plus TCP 80, 443 even though netstat does not show these ports? Im confused. Im referring to this article: https://support.rockstargames.com/hc/de/articles/200525767-GTA-Online-Verbindungsprobleme

– Black – 2017-04-02T18:08:49.443

@Black - maybe you can post this as a new question so it will attract audience able to answer it correctly. Either on this site or on gaming.stackexchange.com. Maybe it is already answered there, perhaps also try searching a bit.

– miroxlav – 2017-04-02T22:35:47.617

@miroxlav i searched the whole internet for it for a long time. But there are no official answers. I guess I have to ask the rockstar support but from my experience they distract and avoid to answer for whatever reasons. – Black – 2017-04-03T06:18:22.150

6

If you are using windows you can use the free utility "Process Explorer" for this - among many other things. You have to run it in Administrator mode though.

enter image description here

Mike Wise

Posted 2017-03-25T17:19:51.050

Reputation: 323

1

If you are wanting to optimize something like a game or netflix streaming, then you don't need to worry about the port on your computer - that is the client, and is (somewhat) randomly chosen from the higher range of ports. What you want is to find out what port(s) the service you are connecting to is provided on, and optimize connections to those ports from your machine (possibly by MAC address? or local lan ip)

Most game server browsers will show port information, or you can always connect to whatever service and then open a terminal window (start -> cmd.exe) and use netstat to find out what programs are connecting to what ports on what IP addresses. Here's a link to the docs for the windows version of it - https://commandwindows.com/netstat.htm

ivanivan

Posted 2017-03-25T17:19:51.050

Reputation: 2 634