djhenderson / dpkt

Automatically exported from code.google.com/p/dpkt
Other
1 stars 0 forks source link

Example Request - Control Type Packets - Destination/Source Addresses #127

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
Trying to attain the destination and source MAC addresses for "Control Type" 
packets

What version of the product are you using? On what operating system?
DPKT v1.8 on Windows 7

Please provide any additional information below.
General code....
import dpkt

f = open('/home/timur/Downloads/Capture-06302014.pcap')
pc = dpkt.pcap.Reader(f)
for ts, buf in pc:
    rt = dpkt.radiotap.Radiotap(buf)
    wlanData = rt.data
    wlanType = wlanData.type

    if(wlanType == dpkt.ieee80211.MGMT_TYPE): 
        # Get the Destination MAC Address
        wlanPackMgmtDest = ':'.join(x.encode('hex') for x in wlanData.mgmt.dst)
        print("WLAN-Pack-Mgmt-Destination: " + repr(wlanPackMgmtDest))

        # Get the Source MAC Address
        wlanPackMgmtSrc = ':'.join(x.encode('hex') for x in wlanData.mgmt.src)
        print("WLAN-Pack-Mgmt-Source: " + repr(wlanPackMgmtSrc))

    elif(wlanType == dpkt.ieee80211.DATA_TYPE):   
        # Get the Destination MAC Address
        wlanPackDataDest = ':'.join(x.encode('hex') for x in wlanData.data_frame.dst)
        print("WIFI Data-Dest: " + repr(wlanPackDataDest))

        # Get the Source MAC Address
        wlanPackDataSrc = ':'.join(x.encode('hex') for x in wlanData.data_frame.src)
        print("WIFI Data-Src: " + repr(wlanPackDataSrc))
    elif(wlanType == dpkt.ieee80211.CTL_TYPE):
        # QUESTION HERE - how do you print the destination and source address of a "CTL_TYPE" package?

Original issue reported on code.google.com by kokopell...@gmail.com on 7 Jul 2014 at 7:08

GoogleCodeExporter commented 9 years ago
That depends on the frame subtype. For example, the following code will prevent 
the destination for the CTS frames and source/destination for the RTS frames:

if ieee.type == dpkt.ieee80211.CTL_TYPE and ieee.subtype == 
dpkt.ieee80211.C_CTS:
    print "CTS -- dst: ", print_addr(ieee.cts.dst)
if ieee.type == dpkt.ieee80211.CTL_TYPE and ieee.subtype == 
dpkt.ieee80211.C_RTS:
    print "RTS -- src: ", print_addr(ieee.rts.src), " dst: ", print_addr(ieee.rts.dst)

There is no generic Control frame header and, hence, the subtype inspection is 
required.

Original comment by timur.al...@gmail.com on 8 Jul 2014 at 1:15

GoogleCodeExporter commented 9 years ago
Oh okay, that makes sense. So for the "CTL_TYPE" packets, I'll have to
parse out the data I'm looking for on a per subtype basis. That makes
sense. Thanks for the information!

Original comment by kokopell...@gmail.com on 8 Jul 2014 at 3:09

GoogleCodeExporter commented 9 years ago

Original comment by timur.al...@gmail.com on 8 Jul 2014 at 4:24

GoogleCodeExporter commented 9 years ago
I can confirm the new code changes work. Thank you!

Original comment by kokopell...@gmail.com on 15 Jul 2014 at 12:31