Code Monkey home page Code Monkey logo

ipgetter2's Introduction

ipgetter2

https://travis-ci.org/starofrainnight/ipgetter2.svg?branch=master https://ci.appveyor.com/api/projects/status/github/starofrainnight/ipgetter2?svg=true

Utility to fetch your external IP address.

This module is designed to fetch your external IP address from the internet.

It is used mostly when behind a NAT.

It picks your IP randomly from a server list to minimize request overhead on a single server

NOTICE: This library is try to act as a replacement of the ipgetter library, because that library has disappeared on pypi.org and github.

  • License: Apache-2.0

Why there another ipgetter library?

I found ipgetter disappeared at night of 2019-05-11. I don't know precisely when it's disappeared, and don't know what's going on.

So I write this library with same API interface for my projects that depends on it as a replacement, hope it will help people that ran into the same situation.

Features

  • Correctly detect webpage encoding by chardet
  • Control the timeout by library requests not by signal alarm (Alarm signal will cause problems)
  • Smart server fetch algorithm, the get() method will fetch at least 2 IP with the same value in 3 random servers (return the only one valid IP without checking if there have only one server responsed)
  • Support IPv6 either (Return both values if the server provided two of them)

Usage

  • ipgetter2 usage
>>> from ipgetter2 import IPGetter
>>> getter = IPGetter()
>>> getter.get()
{v4:"8.8.8.8", v6:"::"}
>>> getter.get_from("http://checkip.dyndns.org/plain")
{v4:"8.8.8.8", v6:"::"}
>>> getter.test()
Numbers of Servers : 46
[1/46] Testing : http://ip.dnsexit.com
[2/46] Testing : http://ifconfig.me/ip
[3/46] Testing : http://ipecho.net/plain
......
[45/46] Testing : http://httpbin.org/ip
[46/46] Testing : https://api.myip.com
8 server failed : ['http://checkip.dyndns.org/plain', 'http://www.canyouseeme.org/', 'http://whatsmyip.net/', 'http://www.ip-adress.com/', 'http://ip-lookup.net/', 'https://check.torproject.org/', 'https://www.privateinternetaccess.com/pages/whats-my-ip/', 'http://myexternalip.com/']
{IPAddress(v4="117.117.117.117", v6="::"): 26, IPAddress(v4="0.0.0.0", v6="::"): 11, IPAddress(v4="117.117.117.116", v6="::"): 1}
IP's : {v4:"117.117.117.117", v6:"::"} = 26 ocurrencies
  • Emulated API interface of ipgetter library
>>> from ipgetter2 import ipgetter1 as ipgetter
>>> myip = ipgetter.myip()
>>> myip
'8.8.8.8'
>>> ipgetter.IPgetter().test()
Number of servers: 47
IP's :
8.8.8.8 = 47 ocurrencies

Credits

This package was created with Cookiecutter and the PyPackageTemplate project template.

ipgetter2's People

Contributors

starofrainnight avatar fabaff avatar

Stargazers

 avatar Shankar Sivarajan avatar Andrés avatar Boban Kilvin avatar dbaspider avatar  avatar Ben avatar David Nicholson avatar

Watchers

James Cloos avatar  avatar  avatar Sergey Ibragimov avatar

ipgetter2's Issues

ipgetter2 does not work on Python 3.5

  • ipgetter2 version: 1.1.8
  • Python version: 3.5.3
  • Operating System: Debian 9.9

Description

ip = IPGetter().get()

which leads to

Traceback (most recent call last):
  File "/etc/nginx/update-cloudflare-dns.py", line 10, in <module>
    ip = IPGetter().get()
  File "/usr/local/lib/python3.5/dist-packages/ipgetter2/ipgetter2.py", line 304, in get
    urls = random.choices(list(rest_urls), k=batch_size)
AttributeError: module 'random' has no attribute 'choices'

It would appear that random.choices is not present on Python 3.5.

ModuleNotFoundError: No module named '_ctypes'

  • ipgetter2 version: 1.1.10
  • Python version: 3.7
  • Operating System: centos6

Description

pip install error

    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

https://bugs.python.org/issue31652

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

[ipgetter2.py] [line 212] NoneType Object has no attribute 'Upper'

  • ipgetter2 version: 1.1.9
  • Python version: 3.6.5
  • Operating System: Deepin 15.11 (based on Debian)

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

I have a script, which fetches my IP address from ipgetter2, to be used with geolite. Once in a while, the script crashes at line 212 of ipgetter2.py in function "get_from()"

Paste the command(s) you ran and the output.

from ipgetter2 import IPGetter
getter = IPGetter()
myIPObj = getter.get()
myIP = myIPObj.v4.compressed

If there was a crash, please include the traceback here.

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/advention/.local/lib/python3.6/site-packages/ipgetter2/ipgetter2.py", line 252, in fetch_address_thread
    address = self.get_from(url)
  File "/home/advention/.local/lib/python3.6/site-packages/ipgetter2/ipgetter2.py", line 212, in get_from
    if guessed["encoding"].upper() == "GB2312":
AttributeError: 'NoneType' object has no attribute 'upper'

I believe adding a try/except block might resolve the issue.

IP_URLS error

  • ipgetter2 version:
  • Python version:
  • Operating System:

Description

http://www.taobao.com/help/getip.php
return taobao callback ip not client ip

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.