Python Regex, Match the last ip octet

195 Views Asked by At

i'm trying to match the last octet of an ip address but it doesn't work.

import dpkt
import socket
import re


def show_http_ip_info(pcap):
    for (ts, buf) in pcap:
        try:
            eth = dpkt.ethernet.Ethernet(buf)
            ip = eth.data
            src = socket.inet_ntoa(ip.src)
            tcp = ip.data
            if tcp.dport == 80 and len(tcp.data) > 0 and src == '140.80.9.'+re.match(r"\d{0,3}", src):
                http = dpkt.http.Request(tcp.data)
                print('\nUser-Agent: ' + http.headers['user-agent'])
                print('Host: ' + http.headers['host'])
                print('Source IP: {}'.format(src))
                print('\n..........................')

        except:
            pass

am i missing something ?? Thanks for your help

0

There are 0 best solutions below