Created
August 18, 2020 10:21
-
-
Save leeyoungseok/5da46434d9a3c94ec2e4f262714ee589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
from scapy.layers.dns import DNSRR, DNS, DNSQR | |
packet = IP()/TCP() | |
Ether()/packet | |
ls(IP, verbose=True) | |
p = Ether()/IP(dst="www.google.com")/TCP() | |
print(p.summary()) | |
print(p.dst) # first layer that has an src field, here Ether | |
print(p[IP].src) # explicitly access the src field of the IP layer | |
print(p[IP].dst) # explicitly access the src field of the IP layer | |
# sprintf() is a useful method to display fields | |
print(p.sprintf("%Ether.src% > %Ether.dst%\n%IP.src% > %IP.dst%")) | |
print(p.sprintf("%TCP.flags% %TCP.dport%")) | |
[p for p in IP(ttl=(1,5))/ICMP()] | |
p=sr1(IP(dst="8.8.8.8")/UDP()/DNS(qd=DNSQR())) | |
p[DNS].an | |
if p.haslayer(DNS): | |
if p.qdcount > 0 and isinstance(p.qd, DNSQR): | |
name = p.qd.qname | |
elif p.ancount > 0 and isinstance(p.an, DNSRR): | |
name = p.an.rdata | |
print(name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment