Suradnik:4ndY/tcom-get-ip
Izvor: HrOpenWiki
(Preusmjereno s Suradnik:4ndY/get-ip-tcom)
Ovaj program u Pythonu dohvaća vanjski IP trenutne konekcije na Internet preko T-coma sa user.t-com.hr. Vjerojatno je potrebno instalirati i dodatan paket BeautifulSoup za parsiranje HTML-a.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
def remove_html_tags( s ):
p = re.compile(r'<.*?>')
return p.sub( '', s )
username = 'nesto' # korisnicko ime
passwd = 'nesto' # zaporka
login_data = { 'username' : username, 'passwd' : passwd }
post = urllib.urlencode( login_data )
auth_handler = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener( auth_handler )
urllib2.install_opener( opener )
try:
f = opener.open('https://user.t-com.hr/index.php', post )
data = f.read()
f.close()
except urllib2.URLError, e:
print e.reason
soup = BeautifulSoup( data )
ip = soup.findAll('b')[5].string
print ip