歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> 用 pystun 獲取局域網的NAT類型和公網IP

用 pystun 獲取局域網的NAT類型和公網IP

日期:2017/3/6 9:27:29   编辑:學習Linux

用 pystun 獲取局域網的NAT類型和公網IP


用 pystun 獲取局域網的NAT類型和公網IP


pystun是一個STUN客戶端工具,用於獲取局域網的NAT類型和公網IP。
A Python STUN client for getting NAT type and external IP (RFC 3489)


pystun的下載地址:https://pypi.python.org/pypi/pystun
到該地址下載pystun的源代碼:pystun-0.1.0.tar.gz

下面講述在Linux系統上安裝pystun,首先要確定安裝了Python。
1. 解壓pystun-0.1.0.tar.gz
[root@localhost]# tar -xzvf pystun-0.1.0.tar.gz
2. 進入源代碼目錄執行安裝命令。
[root@localhost]# cd pystun-0.1.0
[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

如果出現上面“ImportError: No module named setuptools”錯誤,就安裝 python-setuptools。
[root@localhost pystun-0.1.0]# yum -y install python-setuptools
... ...
Installed:
python-setuptools.noarch 0:0.6.10-3.el6

Complete!

安裝setuptools成功後再執行步驟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. 至此安裝pystun完成,執行pystun看能不能獲取NAT類型和公網IP。
[root@localhost pystun-0.1.0]# pystun
Traceback (most recent call last):
... ...
ImportError: No module named argparse

如果出現上述“ImportError: No module named argparse”錯誤,就安裝argparse,如下:
[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

完成argparse安裝,執行pystun獲取NAT類型和公網IP。
[root@localhost pystun-0.1.0]# pystun
NAT Type: Restric NAT
External IP: 119.165.58.156
External Port: 54320

成功啦!

本文永久更新鏈接地址:

http://xxxxxx/Linuxjc/1145144.html TechArticle

Copyright © Linux教程網 All Rights Reserved