This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Syntax for Multiple Ports In Filter

0

I am trying look for all the ports used by Fifa 12. I am using https://help.ea.com/article/fifa-12-online-ports for the information. Is this the best way look for the information for a PC communications as follows?

(udp.port==9565)||(udp.port==9570)||(udp.port==6000)||(tcp.port==9946)||(tcp.port==9988)||(tcp.port==42124)||(tcp.port>=10000)||(tcp.port<=20000)

asked 07 May '12, 17:56

Perceptus's gravatar image

Perceptus
10226
accept rate: 0%


2 Answers:

1

If one uses tcp.port, then both source and destination port will match, which makes it impossible to define a valid range, as the source port will be random and might match as well (and possibly more often than the intended destination port)

This rather long filter will match better (tested on the sample below):

udp.port==9565 or udp.port==9570 or udp.port==6000 or tcp.port==9946 or tcp.port==9988 or tcp.port==42124 or ((tcp.dstport>=10000 and tcp.dstport<=20000) or (tcp.srcport>=10000 and tcp.srcport<=20000))

BEWARE: You need both tcp.dstport and tcp.srcport, to get packets of both directions.

This filter will also match for source ports in that range. However, you can't prevent that without further scripting.

EDIT: Test file: http://cloudshark.org/captures/bd90209e690f

The display filter can be tested within cloudshark ;-) If you apply the filter, you won't see packets with port 30000, which appear first in frame 87. With the filter 'tcp.flags eq 0x02' you will see the ports used in that capture file.

EDIT2: As Jasper already mentioned above, this filter will do as well :-))

udp.port==9565 or udp.port==9570 or udp.port==6000 or tcp.port==9946 or tcp.port==9988 or tcp.port==42124 or (tcp.port>=10000 and tcp.port<=20000)

as it's equivalent to my much longer filter! Sorry for any confusion ;-)

Regards
Kurt

answered 08 May '12, 01:56

Kurt%20Knochner's gravatar image

Kurt Knochner ♦
24.8k1039237
accept rate: 15%

edited 08 May '12, 03:28

That is excellent information. Can I use that also for a capture filter?

(08 May '12, 11:34) Perceptus

Yes, but the syntax is different.

udp port 9565 or udp port 9570 or udp port 6000 or tcp port 9946 or tcp port 9988 or tcp port 42124 or tcp portrange 10000-20000

portrange works at least with 1.7.1. (just tested). If it does not work with an earlier versions (not checked), please upgrade.

(08 May '12, 22:17) Kurt Knochner ♦

0

That last bit "(tcp.port>=10000)||(tcp.port<=20000)" just opens up the filter to all TCP ports.

answered 08 May '12, 01:07

Jaap's gravatar image

Jaap ♦
11.7k16101
accept rate: 14%

probably the "or" should be an "and", but then the range needs to be put in additional brackets.

(08 May '12, 01:15) Jasper ♦♦