用 pystun 擷取區域網路的NAT類型和公網IP

來源:互聯網
上載者:User

用 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

成功啦!

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.