Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psutil, time, json, ast, re
- from IPy import IP
- from tikapy import TikapyClient, ApiError, ClientError
- from pprint import pprint
- listName = "steam-netblocks"
- processName = "steam_osx"
- rosLogin = "god"
- rosPassword = "donotmasturb"
- rosIP = "192.168.88.1"
- rosPort = 8729 #without SSL
- pids = []
- ipsInList = []
- for proc in psutil.process_iter():
- try:
- pinfo = proc.as_dict(attrs=['pid', 'name'])
- if pinfo['name'] == processName:
- pids.append(pinfo['pid'])
- except psutil.NoSuchProcess:
- print("Process not found.")
- break
- while True:
- for pid in pids:
- p = psutil.Process(pid)
- for connection in p.connections():
- if connection.status == 'ESTABLISHED':
- remoteIP = connection.raddr[0]
- remotePort = connection.raddr[1]
- if IP(remoteIP).iptype() != 'PRIVATE' and not (remoteIP in ipsInList):
- try:
- client = TikapyClient(rosIP)
- client.login(rosLogin, rosPassword)
- pprint(client.talk(['/ip/firewall/address-list/add', '=list=' + listName, '=address=' + remoteIP]))
- except ClientError as e:
- _er = str(e.__context__)
- error = json.loads(json.dumps(ast.literal_eval(_er)))
- if re.search(r"already have such entry", error["message"]):
- ipsInList.append(remoteIP)
- pass
- except Exception as e:
- print(e)
- break
- print("Address: " + str(remoteIP) + " added to list. \n")
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement