This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasns.py
executable file
·140 lines (133 loc) · 3.58 KB
/
asns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
from confluent_kafka import Consumer
import flow_messages_enriched_pb2 as api # this needs to be in the local path
import sys
import ipaddress
from collections import defaultdict
from ssl import get_default_verify_paths
with open("./authdata","r") as f:
lines = f.readlines()
group = lines[0].strip()
username = lines[1].strip()
password = lines[2].strip()
consumer = Consumer(
{
"bootstrap.servers": "kafka01.bwnf.belwue.de:9093,kafka02.bwnf.belwue.de:9093,kafka03.bwnf.belwue.de:9093,kafka04.bwnf.belwue.de:9093,kafka05.bwnf.belwue.de:9093",
"group.id": group,
"security.protocol": "sasl_ssl",
"ssl.ca.location": get_default_verify_paths().cafile,
"sasl.mechanisms": "PLAIN",
"sasl.username": username,
"sasl.password": password,
}
)
consumer.subscribe(['flow-messages-enriched'])
a = {
70: "National Library Medicine USA",
43: "Brookhaven National Laboratory",
174: "Cogent",
513: "CERN",
559: "SWITCH",
680: "DFN",
702: "Verizon",
714: "Apple",
786: "JANET",
1239: "Sprint",
1273: "Vodafone",
1297: "CERN",
1299: "Telia",
1754: "DESY",
2018: "AFRINIC",
2603: "NORDUnet",
2906: "Netflix",
2914: "NTT",
3209: "Vodafone",
3257: "GTT",
3303: "Swisscom",
3320: "Deutsche Telekom",
3356: "CenturyLink",
4356: "Epic Games",
5430: "freenet",
5501: "Fraunhofer",
5511: "Orange",
6185: "Apple",
6453: "TATA",
6507: "Riot Games",
6724: "Strato",
6735: "sdt.net",
6805: "Telefonica",
6830: "Vodafone",
6939: "Hurricane Electric",
7018: "AT&T",
8068: "Microsoft",
8075: "Microsoft",
8220: "Colt",
8403: "Spotify",
8560: "1&1",
8674: "Netnod",
8763: "DENIC",
8881: "Versatel",
9009: "GLOBALAXS",
10310: "Yahoo",
13030: "Init7",
13335: "Cloudflare",
15133: "Verizon",
15169: "Google",
16276: "OVH",
16509: "Amazon",
16625: "Akamai",
19679: "Dropbox",
20446: "Highwinds",
20504: "RTL",
20677: "imos",
20940: "Akamai",
22822: "Limelight",
24940: "Hetzner",
30361: "Swiftwill",
31334: "Kabel Deutschland",
32590: "Valve Steam",
32934: "Facebook",
33915: "Vodafone",
35402: "ecotel",
36459: "Github",
36561: "Youtube",
39702: "S-IT",
41552: "Ebay",
41690: "Dailymotion",
46489: "Twitch",
48918: "Globalways",
54113: "Fastly",
54994: "QUANTIL",
57976: "Blizzard",
58069: "KIT",
60781: "Leaseweb",
61339: "LHC",
197540: "Netcup",
197602: "TV-9",
206339: "Schuler Pressen",
}
b = defaultdict(int)
try:
while True:
raw = consumer.poll()
if raw.error():
continue
flowmsg = api.FlowMessage()
flowmsg.ParseFromString(raw.value())
# TODO: beliebige Filter hier, z.B.
# if flowmsg.Peer == "Cogent":
# print(ipaddress.ip_address(flowmsg.DstIP))
# oder einfach alle printen:
if flowmsg.FlowDirection == 0 and flowmsg.SrcAS not in a.keys():
if flowmsg.SrcAS > 64512 and flowmsg.SrcAS < 65534:
print(flowmsg)
b[flowmsg.SrcAS] += flowmsg.Bytes
elif flowmsg.FlowDirection == 1 and flowmsg.DstAS not in a.keys():
if flowmsg.DstAS > 64512 and flowmsg.DstAS < 65534:
print(flowmsg)
b[flowmsg.DstAS] += flowmsg.Bytes
except KeyboardInterrupt:
ranked = sorted(b.items(), key=lambda kv: kv[1], reverse=True)[:50]
for (asn, vol) in ranked:
print("as{}".format(asn), vol/1024**2)
consumer.close()