簡體   English   中英

scapy :: traceroute設置源IP地址

[英]scapy::traceroute setting source ip address

我有一個設置,其中我的源服務器使用任播地址連接到網絡,因此,每次ping或traceroute我連接到的網絡中的任何目的地時,都需要使用源ip。

我目前正在實驗scapy並使用sr方法,但是scapy中的traceroute具有一些我需要使用的強大功能。 scapy中的traceroute不像sr方法那樣使用任何源地址。

有沒有解決的辦法? 還是在scapy :: traceroute之上有任何包裝允許我這樣做?

查看Scapytraceroute函數的代碼表明,它非常簡單,而其大多數強大的功能都位於TracerouteResult類中,該類使用從一個簡單的sr調用接收到的結果實例化,如當前實現所示:

@conf.commands.register
def traceroute(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4 = None, filter=None, timeout=2, verbose=None, **kargs):
    """Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None
"""
    if verbose is None:
        verbose = conf.verb
    if filter is None:
        # we only consider ICMP error packets and TCP packets with at
        # least the ACK flag set *and* either the SYN or the RST flag
        # set
        filter="(icmp and (icmp[0]=3 or icmp[0]=4 or icmp[0]=5 or icmp[0]=11 or icmp[0]=12)) or (tcp and (tcp[13] & 0x16 > 0x10))"
    if l4 is None:
        a,b = sr(IP(dst=target, id=RandShort(), ttl=(minttl,maxttl))/TCP(seq=RandInt(),sport=sport, dport=dport),
                 timeout=timeout, filter=filter, verbose=verbose, **kargs)
    else:
        # this should always work
        filter="ip"
        a,b = sr(IP(dst=target, id=RandShort(), ttl=(minttl,maxttl))/l4,
                 timeout=timeout, filter=filter, verbose=verbose, **kargs)

    a = TracerouteResult(a.res)
    if verbose:
        a.show()
    return a,b

因此,您可以以與此處執行的方式類似的方式調用sr ,但也使用源地址,並將結果傳遞給TracerouteResult類,以利用其強大的功能。

注意:可以將等效方法應用於ScapyIPv6traceroute6函數的代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM