First time here? Check out the FAQ!
THIS IS A TEST INSTANCE. Feel free to ask and answer questions, but take care to avoid triggering too many notifications.
0

How to filter for partial IP such as 50.xxx.xxx.152

Hi, New to Wireshark and am looking to filter traffic to/from a partial IP address, 50.xxx.xxx.152.

What is the correct syntax? ip.host matches "\.152$" gets me the last octet but need to filter on the first as well.

Thanks, H

asked 2018-10-24 14:29:10 +0000
This post is a wiki. Anyone with karma >750 is welcome to improve it.
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

2

Try this filter instead:

(ip.src[0]==32 && ip.src[3]==98) || (ip.dst[0]==32 && ip.dst[3]==98)

Those values, 32 and 98 are hexadecimal values for 50 and 152, respectively. The filter uses the slice operator [] to isolate the 1st and 4th bytes of the source and destination IP address fields. This filter also avoids any potential problems with whether name resolution is enabled or not, as ip.host isn't necessarily guaranteed to match "\.152$" if name resolution is enabled.

Note that you might be tempted to use a simpler filter such as:

ip.addr[0]==32 && ip.addr[3]==98

Unfortunately, this doesn't work reliably because it will actually match either the 1st byte of either the source or destination addresses as well as the 4th byte of either the source or destination IP addresses. For example, if the source address was 50.xxx.xxx.100 and the destination address was 100.xxx.xxx.152, then the packet would still match the filter, as the 1st byte of the source address would match as well as the last byte of the destination address.

Refer to the wireshark-filter man page for more information about the slice operator and Wireshark display filters in general.

cmaynard's avatar
11.1k
cmaynard
answered 2018-10-24 14:56:34 +0000, updated 2018-10-25 21:00:32 +0000
edit flag offensive 0 remove flag delete link

Comments

Great, this seems to work for the display filter. Is there an equivalent for the capture filter?

Henri's avatar Henri (2018-10-24 15:16:49 +0000) edit

For a capture filter, you'd use a very similar construct, such as:

(ip[12]=50 && ip[15]=152) || (ip[16]=50 && ip[19]=152)

Refer to Section 3.1 of RFC791 for the IPv4 header format (and offsets to the relevant source and destination IP address fields) and to the pcap-filter man page for more information on capture filters.

cmaynard's avatar cmaynard (2018-10-24 16:05:20 +0000) edit

Great! Thank you so much!

H

Henri's avatar Henri (2018-10-24 16:37:14 +0000) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer