Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check CDN ips #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Tools for use in supporting the operation of Satellite 6

##### Tools
- [check-perf-tuning](#check-perf-tuning)
- [check-perf-tuning](#check-perf-tuning)
- [check-cdn-ips](#check-cdn-ips)
- [mongo-benchmark](#mongo-benchmark)
- [mongo-size-report](#mongo-size-report)
- [postgres-monitor](#postgres-monitor)
Expand All @@ -18,6 +19,10 @@ Tools for use in supporting the operation of Satellite 6

Utility to check performance tuning parameters on your Satellite 6 server.

## [check-cdn-ips](check-cdn-ips)

Utility to check if Satellite has access to a list of ips.

## [mongo-benchmark](mongo-benchmark)

Utility used for checking IO speed specific to MongoDB. See:
Expand Down
85 changes: 85 additions & 0 deletions check-cdn-ips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/python

import socket
import argparse
import sys
import re
try:
import requests
except ImportError:
print('Please install the python-requests module.')
sys.exit(-1)

output = ([],[])

def get_json(url):
# Performs a GET using the passed URL location
try:
r = requests.get(url, timeout=15, verify=args.verify)
r = r.json()
ip_list = []
for x in r['cidr_list']:
ip = re.search('\d+.\d+.\d+.\d+', x['ip_prefix'])
ip_list.append(ip.group())
except ValueError:
print ("Json was not returned. Not Good!")
sys.exit()
return ip_list

def target_path(path):
print(path)
ip_list = []
ip = open(path)
try:
for x in ip:
x = re.search('\d+.\d+.\d+.\d+', x)
ip_list.append(x.group())
finally:
ip.close()
return ip_list

def scan(target):
print('\n' + ' Starting Scan For ' + str(target))
scan_ip(target, args.port, args.timeout)

def scan_ip(ipaddress, port, timeout):
socket.setdefaulttimeout(timeout)
try:
sock = socket.socket()
sock.connect((ipaddress, port))
print("[ + ] Access " + str(ipaddress))
output[0].append(str(ipaddress))
sock.close()
except:
print("[ - ] Denied " + str(ipaddress))
output[1].append(str(ipaddress))
pass

if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument("--verify", default=False, help="Ignore untrusted CA")
parser.add_argument("--timeout", type=int, default=1, help="Port timeout")
parser.add_argument("--port", type=int, default=443, help="What port to scan against")
parser.add_argument("--api", default="https://access.redhat.com/sites/default/files/cdn_redhat_com_cac.json", help="URL for API Call. Default is https://access.redhat.com/sites/default/files/cdn_redhat_com_cac.json")
parser.add_argument("--path", default=None, help="Use file, if API is blocked. Use full path to file.")
args = parser.parse_args()

if args.path is not None:
targets = target_path(args.path)
for x in targets:
if x != '':
scan(x)
print ('----------Access----------')
print (output[0])
print ('----------Denied----------')
print (output[1])
else:
print (args.api)
targets = get_json(args.api)
for x in targets:
if x != '':
scan(x)
print ('----------Access----------')
print (output[0])
print ('----------Denied----------')
print (output[1])