1
1
#!/usr/bin/env python3
2
2
3
+ import os
3
4
import re
4
5
import requests
5
6
import subprocess
10
11
requests .packages .urllib3 .disable_warnings (InsecureRequestWarning )
11
12
12
13
# Import static data
13
- from core .static import asns
14
14
from core .support import REWRITE
15
15
16
16
# Import parent class
@@ -34,11 +34,26 @@ def __init__(self, workingfile, ip_list, args):
34
34
self .return_data = self ._process_source ()
35
35
36
36
37
+ def _get_source (self ):
38
+ # Read in static source file from static/ dir
39
+ asn_list = []
40
+ pwd = os .path .dirname (os .path .realpath (__file__ ))
41
+ with open (pwd + '/../static/asns.txt' , 'r' ) as _file :
42
+ for line in _file .readlines ():
43
+ line = line .strip ()
44
+ if line != '' and not line .startswith ('#' ):
45
+ asn_list .append (line )
46
+
47
+ return asn_list
48
+
49
+
37
50
def _process_source (self ):
38
- # Individual Company ASNs
39
- # -- @curi0usJack and @violentlydave
40
- # :Format: CompanyName_AS12345
41
- asn_list = asns .asns
51
+ try :
52
+ # Get the source data
53
+ asn_list = self ._get_source ()
54
+ except :
55
+ return self .ip_list
56
+
42
57
asn_list = [x .upper () for x in asn_list ]
43
58
44
59
for asn in asn_list :
@@ -109,15 +124,19 @@ def __init__(self, workingfile, headers, timeout, ip_list, args):
109
124
self .return_data = self ._process_source ()
110
125
111
126
112
- def _get_source (self , asn ):
113
- # Write comments to working file
114
- print ("[*]\t Pulling %s -- %s via BGPView..." % (asn [1 ], asn [0 ]))
115
- self .workingfile .write ("\n \n \t # Live copy of %s ips based on BGPView ASN %s: %s\n " % (
116
- asn [0 ],
117
- asn [1 ],
118
- datetime .now ().strftime ("%Y%m%d-%H:%M:%S" )
119
- ))
127
+ def _get_source (self ):
128
+ # Read in static source file from static/ dir
129
+ asn_list = []
130
+ with open ('../static/asns.txt' , 'r' ) as _file :
131
+ for line in _file .readlines ():
132
+ line = line .strip ()
133
+ if line != '' and not line .startswith ('#' ):
134
+ asn_list .append (line )
135
+
136
+ return asn_list
137
+
120
138
139
+ def _get_data (self , asn ):
121
140
asn_data = requests .get (
122
141
'https://api.bgpview.io/asn/%s/prefixes' % asn [1 ],
123
142
headers = self .headers ,
@@ -130,10 +149,12 @@ def _get_source(self, asn):
130
149
131
150
132
151
def _process_source (self ):
133
- # Individual Company ASNs
134
- # -- @curi0usJack and @violentlydave
135
- # :Format: CompanyName_AS12345
136
- asn_list = asns .asns
152
+ try :
153
+ # Get the source data
154
+ asn_list = self ._get_source ()
155
+ except :
156
+ return self .ip_list
157
+
137
158
asn_list = [x .upper () for x in asn_list ]
138
159
139
160
for asn in asn_list :
@@ -144,10 +165,18 @@ def _process_source(self):
144
165
145
166
try :
146
167
# Get the source data
147
- asn_data = self ._get_source (asn )
168
+ asn_data = self ._get_data (asn )
148
169
except :
149
170
continue
150
171
172
+ # Write comments to working file
173
+ print ("[*]\t Pulling %s -- %s via BGPView..." % (asn [1 ], asn [0 ]))
174
+ self .workingfile .write ("\n \n \t # Live copy of %s ips based on BGPView ASN %s: %s\n " % (
175
+ asn [0 ],
176
+ asn [1 ],
177
+ datetime .now ().strftime ("%Y%m%d-%H:%M:%S" )
178
+ ))
179
+
151
180
try :
152
181
count = 0
153
182
for network in asn_data ['data' ]['ipv4_prefixes' ]:
0 commit comments