Created
April 12, 2018 15:26
-
-
Save BigNerd95/0e4ceef9024d46da0303be7561aee7a9 to your computer and use it in GitHub Desktop.
Ottieni le informazioni della linea TIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# TIMLineInfo by BigNerd95 | |
import requests, xmltodict, sys | |
import lxml.etree as etree | |
TIMurl = "https://187iphone.telecomitalia.it:16443/atsProxy/proxy?service=GetLineInfoService&operation=getLineInfo" | |
TIMpayload = {'xml': '<get:input><xsd:provenienza>iPhone</xsd:provenienza><xsd:tid>0000000000.000000</xsd:tid><xsd1:ip>0.0.0.0</xsd1:ip></get:input>'} | |
#TIMurl = "http://187iphone.telecomitalia.it:16080/atsProxy/proxy?service=GetLineInfoService&operation=getLineInfo" | |
#TIMpayload = {'xml': '<get:input><xsd:provenienza>Windows</xsd:provenienza><xsd:tid>0000000000.000000</xsd:tid><xsd1:ip>0.0.0.0</xsd1:ip></get:input>'} | |
def print_xml(data): | |
print("\nFull XML:\n") | |
x=etree.fromstring(bytes(data, "ascii")) | |
s=etree.tostring(x, pretty_print=True) | |
print(s.decode("ascii")) | |
def parse(data): | |
print("\nINFO:\n") | |
ret = xmltodict.parse(data)['return'] | |
if ret['error']['codice'] == '0': | |
info = ret['response']['lineInfo'] | |
if info: | |
for key, value in info.items(): | |
if value is not None: | |
print(key, '\t', value) | |
else: | |
print("Nessuna informazine, assicurati di essere connesso ad una rete TIM") | |
else: | |
print(ret['error']['descrizione']) | |
def get_line_info(): | |
r = requests.post(TIMurl, data=TIMpayload) | |
return r.text | |
def main(): | |
print("Ottengo info da TIM...") | |
info = get_line_info() | |
if len(sys.argv) > 1 and sys.argv[1] == "-v": | |
print_xml(info) | |
parse(info) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment