swadhingithub init · 1/11/2024
9a08764
45 lines · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests

class IpStack():
    def __init__(self,ipaddress,apikey,*args,**kwerrgs):
        self.ipaddress=ipaddress
        self.apikey=apikey
        self.url=f"http://api.ipstack.com/{ipaddress}?access_key={apikey}&en"
        self.function=args
    
    def get_Apicall(self):
        api=requests.get(self.url).json()
        return api

    
    def getlocation(self):
        api=self.get_Apicall()
        return api["location"]
    
    def hostname_lookup(self):
        lurl=f"{self.url}&hostname=1"
        api=requests.get(lurl).json()
        return api
    
    def api_xmlformat(self):
        url_xml=f"{self.url}&output=xml"
        api=requests.get(url_xml)
        dict_data=api.content
        return dict_data
    
    def callby_function(self,function):
        urlx=f"{self.url}&callback={function}&json"
        txt=requests.get(urlx).text
        import json
        # api=json.loads(txt)
        return txt
    
    def enable_security_apicall(self):
        secureurl=f"{self.url}&security=1"
        api=requests.get(secureurl).json()
        return api
    
    def callby_fields(self,kwerrgs):
        url=f"{self.url}&fields={kwerrgs}"
        api=requests.get(url).json()
        return api