コード例 #1
0
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I",
                      "--ether_iface",
                      dest="ether_iface",
                      default=None,
                      help="The name of the source interface.")

    parser.add_option("-e",
                      "--ether_source",
                      dest="ether_source",
                      default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s",
                      "--ip_source",
                      dest="ip_source",
                      default=None,
                      help="The IP source address.")

    parser.add_option("-G",
                      "--igmp_group",
                      dest="igmp_group",
                      default=None,
                      help="The IPv4 group to spoof a leave message for.")

    parser.add_option("-A",
                      "--no-router-alert",
                      action="store_true",
                      dest="no_ra",
                      help="Disable the use of the IP Router Alert option.")

    (options, args) = parser.parse_args()

    if options.igmp_group is None or \
       options.ether_source is None or \
       options.ether_iface is None or \
       options.ip_source is None:
        print "A required argument is missing."
        return

    output = PcapConnector(options.ether_iface)

    c = ethernet(src=ether_atob(options.ether_source),	\
                 dst=ETHER_MAP_IP_MULTICAST(INADDR_ALLRTRS_GROUP)) / \
        ipv4(flags=IP_DF, id=123, ttl=1, 		\
             src=inet_atol(options.ip_source),		\
             dst=INADDR_ALLRTRS_GROUP) /		\
        igmp(type=IGMP_HOST_LEAVE_MESSAGE) /		\
        igmpv2(group=inet_atol(options.igmp_group))
    c.fixup()

    out = output.write(c.bytes, len(c.bytes))
コード例 #2
0
ファイル: igmp_v2_leave.py プロジェクト: JahanviB/PCS
def main():

    from optparse import OptionParser
    
    parser = OptionParser()

    parser.add_option("-I", "--ether_iface",
                      dest="ether_iface", default=None,
                      help="The name of the source interface.")

    parser.add_option("-e", "--ether_source",
                      dest="ether_source", default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s", "--ip_source",
                      dest="ip_source", default=None,
                      help="The IP source address.")

    parser.add_option("-G", "--igmp_group",
                      dest="igmp_group", default=None,
                      help="The IPv4 group to spoof a leave message for.")

    parser.add_option("-A", "--no-router-alert",
                      action="store_true", dest="no_ra",
                      help="Disable the use of the IP Router Alert option.")

    (options, args) = parser.parse_args()

    if options.igmp_group is None or \
       options.ether_source is None or \
       options.ether_iface is None or \
       options.ip_source is None:
           print "A required argument is missing."
           return

    output = PcapConnector(options.ether_iface)

    c = ethernet(src=ether_atob(options.ether_source),	\
                 dst=ETHER_MAP_IP_MULTICAST(INADDR_ALLRTRS_GROUP)) / \
        ipv4(flags=IP_DF, id=123, ttl=1, 		\
             src=inet_atol(options.ip_source),		\
             dst=INADDR_ALLRTRS_GROUP) /		\
        igmp(type=IGMP_HOST_LEAVE_MESSAGE) /		\
        igmpv2(group=inet_atol(options.igmp_group))
    c.fixup()

    out = output.write(c.bytes, len(c.bytes))
コード例 #3
0
ファイル: igmp_v2_query.py プロジェクト: victorlawn/PCS
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I",
                      "--ether_iface",
                      dest="ether_iface",
                      default=None,
                      help="The name of the source interface.")

    parser.add_option("-e",
                      "--ether_source",
                      dest="ether_source",
                      default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s",
                      "--ip_source",
                      dest="ip_source",
                      default=None,
                      help="The IP source address.")

    parser.add_option("-G",
                      "--igmp_group",
                      dest="igmp_group",
                      default=None,
                      help="The IPv4 group for a group-specific query. "
                      "If omitted, send a general query.")

    parser.add_option("-M",
                      "--maxresp",
                      dest="igmp_maxresp",
                      default=None,
                      help="The maximum time for end-stations to respond "
                      "(in seconds).")

    parser.add_option("-c",
                      "--count",
                      dest="count",
                      default=None,
                      help="Stop after receiving at least count responses.")

    (options, args) = parser.parse_args()

    if options.ether_iface is None or \
       options.ether_source is None or \
       options.ip_source is None or \
       options.count is None:
        print "Non-optional argument missing."
        return

    maxresp = 3 * 10
    if options.igmp_maxresp is not None:
        maxresp = int(options.igmp_maxresp) * 10  # in units of deciseconds

    if options.igmp_group is None:
        # General query.
        dst = INADDR_ALLHOSTS_GROUP
        group = INADDR_ANY
    else:
        # Group-specific query.
        dst = inet_atol(options.igmp_group)
        group = dst

    # Queries don't contain the Router Alert option as they are
    # destined for end stations, not routers.

    c = ethernet(src=ether_atob(options.ether_source),		\
                 dst=ETHER_MAP_IP_MULTICAST(dst)) /		\
        ipv4(flags=IP_DF, ttl=1,				\
             src=inet_atol(options.ip_source),			\
             dst=dst) /						\
        igmp(type=IGMP_HOST_MEMBERSHIP_QUERY, code=maxresp) /	\
        igmpv2(group=group)
    c.fixup()

    input = PcapConnector(options.ether_iface)
    input.setfilter("igmp")

    output = PcapConnector(options.ether_iface)
    out = output.write(c.bytes, len(c.bytes))

    #
    # Wait for up to 'count' responses to the query to arrive and print them.
    #
    count = int(options.count)
    while count > 0:
        packet = input.readpkt()
        chain = packet.chain()
        if chain.packets[2].type == IGMP_v2_HOST_MEMBERSHIP_REPORT:
            #print chain.packets[2].println()
            print "%s is in %s" % \
                (inet_ntop(AF_INET, struct.pack('!L', chain.packets[1].src)), \
                 inet_ntop(AF_INET, struct.pack('!L', chain.packets[3].group)))
            count -= 1
コード例 #4
0
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I",
                      "--ether_iface",
                      dest="ether_iface",
                      default=None,
                      help="The name of the source interface.")

    parser.add_option("-e",
                      "--ether_source",
                      dest="ether_source",
                      default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s",
                      "--ip_source",
                      dest="ip_source",
                      default=None,
                      help="The IP source address.")

    parser.add_option("-G",
                      "--igmp_group",
                      dest="igmp_group",
                      default=None,
                      help="The IPv4 group for a group-specific query. "
                      "If omitted, send a general query.")

    parser.add_option("-S",
                      "--seconds",
                      dest="seconds",
                      default=1.0,
                      help="Number of seconds between packets.")

    parser.add_option("-c",
                      "--count",
                      dest="count",
                      default=None,
                      help="Stop after sending count packets.")

    (options, args) = parser.parse_args()

    if options.ether_iface is None or \
       options.ether_source is None or \
       options.ip_source is None or \
       options.count is None:
        print "Non-optional argument missing."
        return

    maxresp = 3 * 10

    if options.igmp_group is None:
        # General query.
        dst = INADDR_ALLHOSTS_GROUP
        group = INADDR_ANY
    else:
        # Group-specific query.
        dst = inet_atol(options.igmp_group)
        group = dst

    # Queries don't contain the Router Alert option as they are
    # destined for end stations, not routers.

    c = ethernet(src=ether_atob(options.ether_source),		\
                 dst=ETHER_MAP_IP_MULTICAST(dst)) /		\
        ipv4(flags=IP_DF, ttl=1,				\
             src=inet_atol(options.ip_source),			\
             dst=dst) /						\
        igmp(type=IGMP_v2_HOST_MEMBERSHIP_REPORT, code=maxresp) /	\
        igmpv2(group=group)
    c.fixup()

    output = PcapConnector(options.ether_iface)
    #
    # Send count packets, delayed by seconds
    #
    count = int(options.count)
    if count < 0:
        count = sys.maxint
    while count > 0:
        out = output.write(c.bytes, len(c.bytes))
        count -= 1
        sleep(float(options.seconds))
コード例 #5
0
ファイル: igmp_v2_join.py プロジェクト: JahanviB/PCS
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I", "--ether_iface",
                      dest="ether_iface", default=None,
                      help="The name of the source interface.")

    parser.add_option("-e", "--ether_source",
                      dest="ether_source", default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s", "--ip_source",
                      dest="ip_source", default=None,
                      help="The IP source address.")

    parser.add_option("-G", "--igmp_group",
                      dest="igmp_group", default=None,
                      help="The IPv4 group for a group-specific query. "
			   "If omitted, send a general query.")

    parser.add_option("-S", "--seconds",
                      dest="seconds", default=1.0,
                      help="Number of seconds between packets.")

    parser.add_option("-c", "--count",
                      dest="count", default=None,
                      help="Stop after sending count packets.")

    (options, args) = parser.parse_args()

    if options.ether_iface is None or \
       options.ether_source is None or \
       options.ip_source is None or \
       options.count is None:
        print "Non-optional argument missing."
        return

    maxresp = 3 * 10

    if options.igmp_group is None:
	# General query.
    	dst = INADDR_ALLHOSTS_GROUP
        group = INADDR_ANY
    else:
	# Group-specific query.
    	dst = inet_atol(options.igmp_group)
        group = dst

    # Queries don't contain the Router Alert option as they are
    # destined for end stations, not routers.

    c = ethernet(src=ether_atob(options.ether_source),		\
                 dst=ETHER_MAP_IP_MULTICAST(dst)) /		\
        ipv4(flags=IP_DF, ttl=1,				\
             src=inet_atol(options.ip_source),			\
             dst=dst) /						\
        igmp(type=IGMP_v2_HOST_MEMBERSHIP_REPORT, code=maxresp) /	\
        igmpv2(group=group)
    c.fixup()

    output = PcapConnector(options.ether_iface)
    #
    # Send count packets, delayed by seconds
    #
    count = int(options.count)
    if count < 0:
        count = sys.maxint
    while count > 0:
        out = output.write(c.bytes, len(c.bytes))
        count -= 1
        sleep(float(options.seconds))
コード例 #6
0
ファイル: igmp_v2_query.py プロジェクト: JahanviB/PCS
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I", "--ether_iface",
                      dest="ether_iface", default=None,
                      help="The name of the source interface.")

    parser.add_option("-e", "--ether_source",
                      dest="ether_source", default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s", "--ip_source",
                      dest="ip_source", default=None,
                      help="The IP source address.")

    parser.add_option("-G", "--igmp_group",
                      dest="igmp_group", default=None,
                      help="The IPv4 group for a group-specific query. "
			   "If omitted, send a general query.")

    parser.add_option("-M", "--maxresp",
                      dest="igmp_maxresp", default=None,
                      help="The maximum time for end-stations to respond "
			   "(in seconds).")

    parser.add_option("-c", "--count",
                      dest="count", default=None,
                      help="Stop after receiving at least count responses.")

    (options, args) = parser.parse_args()

    if options.ether_iface is None or \
       options.ether_source is None or \
       options.ip_source is None or \
       options.count is None:
        print "Non-optional argument missing."
        return

    maxresp = 3 * 10
    if options.igmp_maxresp is not None:
        maxresp = int(options.igmp_maxresp) * 10    # in units of deciseconds

    if options.igmp_group is None:
	# General query.
    	dst = INADDR_ALLHOSTS_GROUP
        group = INADDR_ANY
    else:
	# Group-specific query.
    	dst = inet_atol(options.igmp_group)
        group = dst

    # Queries don't contain the Router Alert option as they are
    # destined for end stations, not routers.

    c = ethernet(src=ether_atob(options.ether_source),		\
                 dst=ETHER_MAP_IP_MULTICAST(dst)) /		\
        ipv4(flags=IP_DF, ttl=1,				\
             src=inet_atol(options.ip_source),			\
             dst=dst) /						\
        igmp(type=IGMP_HOST_MEMBERSHIP_QUERY, code=maxresp) /	\
        igmpv2(group=group)
    c.fixup()

    input = PcapConnector(options.ether_iface)
    input.setfilter("igmp")

    output = PcapConnector(options.ether_iface)
    out = output.write(c.bytes, len(c.bytes))

    #
    # Wait for up to 'count' responses to the query to arrive and print them.
    #
    count = int(options.count)
    while count > 0:
        packet = input.readpkt()
        chain = packet.chain()
	if chain.packets[2].type == IGMP_v2_HOST_MEMBERSHIP_REPORT:
	    #print chain.packets[2].println()
	    print "%s is in %s" % \
	        (inet_ntop(AF_INET, struct.pack('!L', chain.packets[1].src)), \
	         inet_ntop(AF_INET, struct.pack('!L', chain.packets[3].group)))
	    count -= 1
コード例 #7
0
ファイル: igmp_v2_grouptest.py プロジェクト: JahanviB/PCS
def main():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("-I", "--ether_iface",
                      dest="ether_iface", default=None,
                      help="The name of the source interface.")

    parser.add_option("-e", "--ether_source",
                      dest="ether_source", default=None,
                      help="The host Ethernet source address.")

    parser.add_option("-s", "--ip_source",
                      dest="ip_source", default=None,
                      help="The IP source address.")

    parser.add_option("-G", "--igmp_group",
                      dest="igmp_group", default=None,
                      help="The IPv4 group for a group-specific query. "
			   "If omitted, send a general query.")

    parser.add_option("-M", "--maxresp",
                      dest="igmp_maxresp", default=None,
                      help="The maximum time for end-stations to respond "
			   "(in seconds).")

    parser.add_option("-l", "--host_list",
                      dest="hostlist", action="append",
                      help="List of hosts we expect responses from.")

    parser.add_option("-n", "--number",
                      dest="number", default = 1, type=int,
                      help="Query a number of groups starting at "
                      "the one given by -G")

    parser.add_option("-c", "--count",
                      dest="count", default=None,
                      help="Stop after receiving at least count responses.")

    (options, args) = parser.parse_args()

    if options.ether_iface is None or \
       options.ether_source is None or \
       options.ip_source is None or \
       options.count is None:
        print "Non-optional argument missing."
        return

    maxresp = 3 * 10
    if options.igmp_maxresp is not None:
        maxresp = int(options.igmp_maxresp) * 10    # in units of deciseconds

    if options.igmp_group is None:
	# General query.
    	dst = INADDR_ALLHOSTS_GROUP
        group = INADDR_ANY
    else:
	# Group-specific query.
    	dst = inet_atol(options.igmp_group)
        group = dst

    # Set up our match table
    global match
    match = {}
    for host in options.hostlist:
        for addr in range(group, group + options.number):
            match[(inet_atol(host), (addr))] = False

    signal.signal(signal.SIGINFO, results)

    while (options.number >= 0):

        # Queries don't contain the Router Alert option as they are
        # destined for end stations, not routers.

        c = ethernet(src=ether_atob(options.ether_source),		\
                     dst=ETHER_MAP_IP_MULTICAST(dst)) /		\
            ipv4(flags=IP_DF, ttl=1,				\
                 src=inet_atol(options.ip_source),			\
                 dst=dst + options.number) /   \
            igmp(type=IGMP_HOST_MEMBERSHIP_QUERY, code=maxresp) /	\
            igmpv2(group=(group + options.number))
        c.fixup()

        input = PcapConnector(options.ether_iface)
        input.setfilter("igmp")

        output = PcapConnector(options.ether_iface)
        out = output.write(c.bytes, len(c.bytes))

        options.number -= 1
        
    #
    # Wait for up to 'count' responses to the query to arrive and print them.
    #
    count = int(options.count)
    while count > 0:
        packet = input.readpkt()
        chain = packet.chain()
	if chain.packets[2].type == IGMP_v2_HOST_MEMBERSHIP_REPORT:
	    #print chain.packets[2].println()
	    # print "%s is in %s" % \
	    #     (inet_ntop(AF_INET, struct.pack('!L', chain.packets[1].src)), \
	    #      inet_ntop(AF_INET, struct.pack('!L', chain.packets[3].group)))
            match[(chain.packets[1].src, chain.packets[3].group)] = True
	    count -= 1

    results(0, 0)