Exemple #1
0
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
except socket.error, msg:
    print 'Socket could not be created. Error Code : ' + str(msg[0])\
        + ' Message ' + msg[1]
    sys.exit()

# tell kernel not to put in headers, since we are provpkt_iding it
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

# now start constructing the packet
packet = ''

source_ip = streams.stdin.readline().strip()
dest_ip = streams.stdin.readline().strip()
streams.log('src: %s, dst: %s', source_ip, dest_ip)

# source_ip = '192.168.1.101'
#dest_ip = '192.168.1.1'  # or socket.gethostbyname('www.google.com')

# ip header fields
ihl = 5
version = 4
tos = 0
# python seems to correctly fill the total length, dont know how ??
tot_len = 20 + 20
pkt_id = 54321  # pkt_id of this packet
frag_off = 0
ttl = 255
protocol = socket.IPPROTO_TCP
check = 10  # python seems to correctly fill the checksum
Exemple #2
0
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
except socket.error, msg:
    print 'Socket could not be created. Error Code : ' + str(msg[0])\
        + ' Message ' + msg[1]
    sys.exit()

# tell kernel not to put in headers, since we are provpkt_iding it
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

# now start constructing the packet
packet = ''

source_ip = streams.stdin.readline().strip()
dest_ip = streams.stdin.readline().strip()
streams.log('src: %s, dst: %s', source_ip, dest_ip)

# source_ip = '192.168.1.101'
#dest_ip = '192.168.1.1'  # or socket.gethostbyname('www.google.com')

# ip header fields
ihl = 5
version = 4
tos = 0
# python seems to correctly fill the total length, dont know how ??
tot_len = 20 + 20
pkt_id = 54321  # pkt_id of this packet
frag_off = 0
ttl = 255
protocol = socket.IPPROTO_TCP
check = 10  # python seems to correctly fill the checksum
Exemple #3
0
    # tell kernel not to put in headers, since we are provpkt_iding it
    return sock


# protos = {
#     'icmp': socket.IPPROTO_ICMP,
#     # 'icmp6': socket.IPPROTO_ICMPV6,
#     'tcp': socket.IPPROTO_TCP,
#     'udp': socket.IPPROTO_UDP,
# }
# create an INET, STREAMing socket
try:
    sock = raw_socket()
    # socket.socket(socket.AF_INET, socket.SOCK_RAW,socket.IPPROTO_TCP)
except socket.error, msg:
    TUBY.log('Exception: Socket could not be created. Error Code : ' +
             str(msg[0]) + ' Message ' + msg[1])
    sys.exit(1)

# receive a packet
while True:
    try:
        #         TUBY.stdout.write(
        #             base64.b64encode(
        #                 sock.recvfrom(65565)[0].strip()) + '\n')
        TUBY.stdout.write(
            base64.b64encode(sock.recvfrom(65565)[0].strip()) + '\n')
    except KeyboardInterrupt:
        print "Ctrl-C"
        break
Exemple #4
0
Fichier : pcap.py Projet : t0z/tuby
    except socket.error, msg:
        raise RuntimeError("Socket could not be created." "\n\tError Code : %s\n\tMessage " % (str(msg[0])), msg[1])
    # tell kernel not to put in headers, since we are provpkt_iding it
    return sock


# protos = {
#     'icmp': socket.IPPROTO_ICMP,
#     # 'icmp6': socket.IPPROTO_ICMPV6,
#     'tcp': socket.IPPROTO_TCP,
#     'udp': socket.IPPROTO_UDP,
# }
# create an INET, STREAMing socket
try:
    sock = raw_socket()
    # socket.socket(socket.AF_INET, socket.SOCK_RAW,socket.IPPROTO_TCP)
except socket.error, msg:
    TUBY.log("Exception: Socket could not be created. Error Code : " + str(msg[0]) + " Message " + msg[1])
    sys.exit(1)

# receive a packet
while True:
    try:
        #         TUBY.stdout.write(
        #             base64.b64encode(
        #                 sock.recvfrom(65565)[0].strip()) + '\n')
        TUBY.stdout.write(base64.b64encode(sock.recvfrom(65565)[0].strip()) + "\n")
    except KeyboardInterrupt:
        print "Ctrl-C"
        break