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

Capture Filter for range of MAC addresses

0

I'm attempting to create a capture filter for a range of MAC addresses.

The range of addresses is: 0009fbx6 where x can be any number

asked 29 May '13, 19:30

Mpking's gravatar image

Mpking
8336
accept rate: 0%


One Answer:

1

You can create a filter that manually looks at the mac address fields in the ethernet header. Here is what the normal "ether host 11:22:33:44:55:66" looks like in BPF code:

$ tcpdump -d ether host 11:22:33:44:55:66
(000) ld       [8]
(001) jeq      #0x33445566      jt 2    jf 4
(002) ldh      [6]
(003) jeq      #0x1122          jt 8    jf 4
(004) ld       [2]
(005) jeq      #0x33445566      jt 6    jf 9
(006) ldh      [0]
(007) jeq      #0x1122          jt 8    jf 9
(008) ret      #65535
(009) ret      #0
$

So in your case, you want to look at the ethernet destination address, which starts at offset o in the ethernet header and you will need the first 4 octets. This can be done with ether[0:4], then you need to mask all the bits in which you are not interested, this can be done with ether[0:4] & 0xffffff0f. Then compare this with your specific address range 0x0009fb06. The same goes for the ethernet source address which can be found at offset 6. This will result in the filter:

 ether[0:4] & 0xffffff0f = 0x0009fb06 or ether[6:4] & 0xffffff0f = 0x0009fb06

This filter will result in the following BPF code:

$ tcpdump -d "ether[0:4] & 0xffffff0f = 0x0009fb06 or ether[6:4] & 0xffffff0f = 0x0009fb06"
(000) ld       [0]
(001) and      #0xffffff0f
(002) jeq      #0x9fb06         jt 6    jf 3
(003) ld       [6]
(004) and      #0xffffff0f
(005) jeq      #0x9fb06         jt 6    jf 7
(006) ret      #65535
(007) ret      #0
$

answered 29 May '13, 23:59

SYN-bit's gravatar image

SYN-bit ♦♦
17.1k957245
accept rate: 20%

Ok. That is very similar with I had come up with, Mine had more brackets.

I'm also trying to do the inverse. Capture all packets, except for 0009fbx6 where x can be any number.

I think my brackets have been getting in the way.

I've tried not (ether[0:4] & 0xffffff0f = 0x0009fb06) or not (ether[6:4] & 0xffffff0f = 0x0009fb06)

But it doesn't seem to exclude those packets.

(30 May '13, 07:06) Mpking
1

It's either:

not (srcfilter or dstfilter)

or

not (srcfilter) and not (dstfilter)

I usualy take the filter that shows me all the traffic I do not want to see and then put "not (" and ")" around it.

So in your case:

not ( ether[0:4] & 0xffffff0f = 0x0009fb06 or ether[6:4] & 0xffffff0f = 0x0009fb06 )
(30 May '13, 07:10) SYN-bit ♦♦

Hmm... That did not appear to work for me. I'm still seeing that traffic.

(08 Jun '13, 20:47) Mpking

Can you share a piece of the full tracefile (without the filter) on www.cloudshark.org?

If not, can you do the following:

  • Create a capture file with 1000 packets (-c 1000) without using a cature filter
  • Use tcpdump to extract a file with the filter (tcpdump -r full.pcap -w incl.pcap "ether[0:4] & 0xffffff0f = 0x0009fb06 or ether[6:4] & 0xffffff0f = 0x0009fb06")
  • Use tcpdump to extract a file with the exclude filter (tcpdump -r full.pcap -w excl.pcap "ether[0:4] & 0xffffff0f = 0x0009fb06 or ether[6:4] & 0xffffff0f = 0x0009fb06")
  • Run capinfos -Tc * and show the output here.
  • Run tshark -nlr excl.pcap -T fields -e eth.src -e eth.dst -c 5 and show the output here.
(08 Jun '13, 23:39) SYN-bit ♦♦

Unfortunately, I can't seem to do either. The box I'm performing the capture's on is on an isolated network, and I don't have access to getting files on or off the box. (I'm supposed to, but something is messed up with my VPN, and I can only seem to get RDP access to the box)

The box is windows, and only has wireshark (WinPCAP / tshark) on the box. I can added tcpdump for the same above reason.

Is there a way to do this with Just wireshark?

I will have a person onsite tomorrow, so there is a possibility that I can get files sneakernet'd off the box tomorrow, but that is iffy, because there supposed to be doing an install of something in a different part of the building.

(09 Jun '13, 18:49) Mpking

Using Remote Desktop you can "share" a local drive with the remote machine, and then on the remote machine copy files to that "shared" drive. Look under Options | Local Resources | Local devices and resources | More ...

(10 Jun '13, 03:07) grahamb ♦
showing 5 of 6 show 1 more comments