Use pystun to obtain the NAT type and public IP address of the LAN
Pystun is a STUN client tool used to obtain the NAT type and public IP address of the LAN.
A Python STUN client for getting NAT type and external IP (RFC 3489)
Pystun: https://pypi.python.org/pypi/pystun
Download the source code: pystun-0.1.0.tar.gz for pystun to this address
The following describes how to install pystun on Linux. First, you must confirm that Python is installed.
1. Decompress pystun-0.1.0.tar.gz
[Root @ localhost] # tar-xzvf pystun-0.1.0.tar.gz
2. Go to the source code directory and run the installation command.
[Root @ localhost] # pystun-0.1.0 cd
[Root @ localhost pystun-0.1.0] # python setup. py install
Traceback (most recent call last ):
File "setup. py", line 2, in <module>
From setuptools import setup, find_packages
ImportError: No module named setuptools
If the above "ImportError: No module named setuptools" error occurs, install python-setuptools.
[Root @ localhost pystun-0.1.0] # yum-y install python-setuptools
......
Installed:
Python-setuptools.noarch 0: 0. 6.10-3. el6
Complete!
After successfully installing setuptools, run the installation command in step 2:
[Root @ localhost pystun-0.1.0] # python setup. py install
Running install
......
Installed/usr/lib/python2.6/site-packages/pystun-0.1.0-py2.6.egg
Processing dependencies for pystun = 0.1.0
Finished processing dependencies for pystun = 0.1.0
3. Install pystun now. Run pystun to check whether the NAT type and public IP address can be obtained.
[Root @ localhost pystun-0.1.0] # pystun
Traceback (most recent call last ):
......
ImportError: No module named argparse
If the above "ImportError: No module named argparse" error occurs, install argparse as follows:
[Root @ localhost pystun-0.1.0] # easy_install argparse
Searching for argparse
......
Installed/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg
Processing dependencies for argparse
Finished processing dependencies for argparse
Install argparse and run pystun to obtain the NAT type and public IP address.
[Root @ localhost pystun-0.1.0] # pystun
NAT Type: Restric NAT
External IP: 119.165.58.156
External Port: 54320
Success!
This article permanently updates the link address: