In this post i will show you how to find your global ip address using python , So why wait let the hacking begin !
First see the code:-
import bs4,requests
def ipadd(url):
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text,"html.parser")
elems = soup.select("body > main:nth-child(1) > div:nth-child(1) > h1:nth-child(1)")
return elems[0].text.strip()
ipis = ipadd("https://ipecho.net/")
print("Your global ip is "+ipis)
Nothing difficult i am going to breakdown the code
first we are importing two modules bs4 aka beautifulsoup and requests
bs4 used for web scrapping .
- we are requesting to a url named 'ipecho.net'
- checking if any error has been raised or not
- scraping the request using bs4
- selecting that html part which has the info we need
- returning the ip in text or string format
It is simple isn't it :)
Top comments (0)