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

Add plugin to find your IP #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions nova3/engines/whats_my_ip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#VERSION: 1.00
# AUTHORS: Qwerty <[email protected]>
# This plugin is useful when you are configuring a VPN and need to verify that it works!

from html.parser import HTMLParser
from helpers import retrieve_url
from novaprinter import prettyPrinter

class whats_my_ip(object):

url = 'https://qwerty.xyz/'
name = "What's my IP?"
supported_categories = {'all': '0'}

service_url = 'http://ipip.cz/'

def search(self, what, cat='all'):
response = retrieve_url(self.service_url)

parser = IPParser()
parser.feed(response)

prettyPrinter({
'link': self.service_url,
'name': f"IP Address: {parser.ip_address}",
# Says "Unknown" and can be sorted to the top by smallest size
'size': -1,
# Sort the result to the top by Seeds
'seeds': 1000001,
'leech': 1337,
'engine_url': self.service_url,
'desc_link': self.service_url,
'pub_date': -1
})

prettyPrinter({
'link': self.service_url,
'name': f"Hostname: {parser.hostname}",
# Says "Unknown" and can be sorted to the top by smallest size
'size': -1,
# Sort the result to the top by Seeds
'seeds': 1000000,
'leech': 1337,
'engine_url': self.service_url,
'desc_link': self.service_url,
'pub_date': -1
})

class IPParser(HTMLParser):
def __init__(self):
super().__init__()
self.in_ip_div = False
self.ip_address = ""
self.hostname = ""
self.data_buffer = []

def handle_starttag(self, tag, attrs):
if tag == 'div':
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'ip':
self.in_ip_div = True

def handle_endtag(self, tag):
if tag == 'div' and self.in_ip_div:
self.in_ip_div = False
data_str = ''.join(self.data_buffer)
self.data_buffer = []
if 'Moje IP adresa:' in data_str:
parts = data_str.split('Moje IP adresa:')
ip_part = parts[1].split('Hostname:')
self.ip_address = ip_part[0].strip()
self.hostname = ip_part[1].strip()

def handle_data(self, data):
if self.in_ip_div:
self.data_buffer.append(data)