Notice: Trying to access array offset on value of type bool in /home1/freesand/public_html/wp-content/plugins/wiki-embed/WikiEmbed.php on line 112

Notice: Trying to access array offset on value of type bool in /home1/freesand/public_html/wp-content/plugins/wiki-embed/WikiEmbed.php on line 112

Notice: Trying to access array offset on value of type bool in /home1/freesand/public_html/wp-content/plugins/wiki-embed/WikiEmbed.php on line 116
FreeSandal | 輕。鬆。學。部落客 | 第 266 頁

勇闖新世界︰ W!o《卡夫卡村》變形祭︰圓局定向‧四

不論用什麼樣的『 金文尺 』尺來度量,都得了解那根尺的構成,以及量到數值的意義,要如何校正資料,方能有實際的用途。為此特別介紹一個稱之為『地壘』 horst 的軟體︰

spiralsun_smallbr1 blog

high-tech or low-life?

horst

“horst” is a small, lightweight IEEE802.11 wireless LAN analyzer with a text interface. Its basic function is similar to tcpdump, Wireshark or Kismet, but it’s much smaller and shows different, aggregated information which is not easily available from other tools. It is mainly targeted at debugging wireless LANs with a focus on ad-hoc (IBSS) mode in larger mesh networks. It can be useful to get a quick overview of what’s going on on all wireless LAN channels and to identify problems.

  • Shows signal (RSSI) values per station
  • Calculates channel utilization (“usage”) by adding up the amount of time the packets actually occupy the medium
  • “Spectrum Analyzer” shows signal levels and usage per channel
  • Graphical packet history, with signal, packet type and physical rate
  • Shows all stations per ESSID and the live TSF per node as it is counting
  • Detects IBSS “splits” (same ESSID but different BSSID – this is a common driver problem)
  • Statistics of packets/bytes per physical rate and per packet type
  • Has some support for mesh protocols (OLSR and batman)
  • Can filter specific packet types, source addresses or BSSIDs
  • Client/server support for monitoring on remote nodes

“horst” is a Linux program and can be used on any wireless LAN monitor interface. The latest version is 4.2 from Oct 1 2014.

……

【主畫面】

horst-main_0

 

【訊號‧雜訊‧歷史】

horst-history_1

 

【頻譜分析】

horst-spec1

 

以期加深讀者對無線網路的認識。由於這個程式使用 IEEE802.11 的『monitor』操作模式,讀者可用『 iw list 』來確認 USB 無線 dongle 是否具有這個模式︰

 

# iw 工具安裝
pi@raspberrypi ~ sudo apt-get install iw  # 如果 iw list 顯示空行,那個 USB WiFi dongle 不具 IEEE802.11 相容模式。  pi@raspberrypi ~ iw list
Wiphy phy0
# ………
# USB WiFi dongle 提供哪些模式
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * WDS
# 有 monitor 模式
		 * monitor
		 * mesh point
	software interface modes (can always be added):
		 * AP/VLAN
		 * monitor
	valid interface combinations:
		 * #{ AP, mesh point } <= 8,
		   total <= 8, #channels <= 1

 

地壘 horst 之安裝及執行︰

# 將 IEEE802.11 的 USB WiFi dongle 設定為 monitor only 模式
pi@raspberrypi ~ iwconfig  wlan0     IEEE 802.11bgn  ESSID:off/any             Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm              Retry short limit:7   RTS thr:off   Fragment thr:off           Power Management:off            lo        no wireless extensions.  eth0      no wireless extensions.  # 刪除 wlan0 managed 模式 pi@raspberrypi ~ sudo iw dev wlan0 del
pi@raspberrypi ~ iwconfig  lo        no wireless extensions.  eth0      no wireless extensions.  # 增加命名為 mono0 的 monitor 模式 pi@raspberrypi ~ sudo iw phy phy0 interface add mon0 type monitor
pi@raspberrypi ~ iwconfig  lo        no wireless extensions.  mon0      IEEE 802.11bgn  Mode:Monitor  Frequency:2.412 GHz  Tx-Power=20 dBm              Retry short limit:7   RTS thr:off   Fragment thr:off           Power Management:off            eth0      no wireless extensions.  # 取得 horst,編譯地壘,以及執行 pi@raspberrypi ~ wget http://br1.einfach.org/horst_dl/horst-4.2.tar.gz
pi@raspberrypi ~ tar -zxvf horst-4.2.tar.gz pi@raspberrypi ~ cd horst-4.2/
pi@raspberrypi ~/horst-4.2 make pi@raspberrypi ~/horst-4.2 sudo ./horst -i mon0

 

 

 

 

 

 

 

 

 

勇闖新世界︰ W!o《卡夫卡村》變形祭︰圓局定向‧三

從實用性來講,要是非得連上『無線阡陌網』,否則不能使用那個『定向器』,除非為了安全顧慮,大概並不方便。那麼將如何用 Python WiFi 來取得 AP 『熱點資訊』 的呢?由於作者不知道哪裡有文件可讀?所以只是依著玩遊戲『過關』之精神,到處看看,隨便試試,這或許就是『互動式』程式的好處吧!略將結果整理如下︰

 

pi@raspberrypi ~ 
*** QuickLaTeX cannot compile formula:
sudo python
Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pythonwifi.iwlibs import Wireless

# 選取 WiFi 裝置
>>> wifi = Wireless('wlan0')

# AP 熱點掃描
>>> iwScan = wifi.scan()

# 探詢掃描物件屬性
>>> dir(iwScan)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_parse', 'aplist', 'getScan', 'ifname', 'index', 'next', 'range', 'stream']

# AP 表列物件
>>> apList = iwScan.aplist

# AP 表列物件屬性
>>> dir(apList[1])
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'addEvent', 'bssid', 'custom', 'display', 'encode', 'essid', 'frequency', 'mode', 'protocol', 'quality', 'range', 'rate']

# 探詢某一 AP 物件
>>> apList[1].essid
'iHOME'
>>> apList[1].bssid
'78:54:2E:FB:77:B0'
>>> apList[1].encode
<pythonwifi.iwlibs.Iwpoint object at 0x767d3630>
>>> apList[1].frequency
<pythonwifi.iwlibs.Iwfreq object at 0x767d3610>
>>> apList[1].mode
'Master'

# 探詢何謂 AP 品質?
>>> apList[1].quality
<pythonwifi.iwlibs.Iwquality object at 0x767d3570>

# 探詢 AP 品質物件屬性
>>> dir(apList[1].quality)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'fmt', 'getNoiselevel', 'getSignallevel', 'nlevel', 'noiselevel', 'parse', 'quality', 'setNoiselevel', 'setSignallevel', 'setValues', 'siglevel', 'signallevel', 'updated']

# 訊號強度?!
>>> apList[1].quality.getSignallevel()
49
>>> 
</pre>
 

<span style="color: #808000;">也許有人會先讀『 iwlist.py 』範例原始碼,畢竟『 iwlist 』指令能夠作 AP 掃描的啊!!</span>

 
<pre class="lang:python decode:true "># iwlist.py 原始碼 scanning 部份

def print_scanning_results(wifi, args=None):
    """ Print the access points detected nearby.

    """
    # "Check if the interface could support scanning"
    try:
        iwrange = Iwrange(wifi.ifname)
    except IOError, (error_number, error_string):
        sys.stderr.write("%-8.16s  Interface doesn't support scanning.\n\n" % (
                            wifi.ifname))
    else:
        # "Check for Active Scan (scan with specific essid)"
        # "Check for last scan result (do not trigger scan)"
        # "Initiate Scanning"
        try:
            results = wifi.scan()
        except IOError, (error_number, error_string):
            if error_number != errno.EPERM:
                sys.stderr.write(
                    "%-8.16s  Interface doesn't support scanning : %s\n\n" %
                    (wifi.ifname, error_string))
        else:
            if (len(results) == 0):
                print "%-8.16s  No scan results" % (wifi.ifname, )
            else:
                (num_channels, frequencies) = wifi.getChannelInfo()
                print "%-8.16s  Scan completed :" % (wifi.ifname, )
                index = 1
                for ap in results:
                    print "          Cell %02d - Address: %s" % (index, ap.bssid)
                    print "                    ESSID:\"%s\"" % (ap.essid, )
                    print "                    Mode:%s" % (ap.mode, )
                    print "                    Frequency:%s (Channel %d)" % \
                        (wifi._formatFrequency(ap.frequency.getFrequency()),
                        frequencies.index(wifi._formatFrequency(
                            ap.frequency.getFrequency())) + 1)
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_QUAL_UPDATED):
                        quality_updated = "="
                    else:
                        quality_updated = ":"
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_LEVEL_UPDATED):
                        signal_updated = "="
                    else:
                        signal_updated = ":"
                    if (ap.quality.updated & \
                                pythonwifi.flags.IW_QUAL_NOISE_UPDATED):
                        noise_updated = "="
                    else:
                        noise_updated = ":"
                    print "                    " + \
                        "Quality%c%s/%s  Signal level%c%s/%s  Noise level%c%s/%s" % \
                        (quality_updated,
                        ap.quality.quality,
                        wifi.getQualityMax().quality,
                        signal_updated,
                        ap.quality.getSignallevel(),
                        "100",
                        noise_updated,
                        ap.quality.getNoiselevel(),
                        "100")
                    # This code on encryption keys is very fragile
                    if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
                        key_status = "off"
                    else:
                        if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
                            if (ap.encode.length <= 0):
                                key_status = "on"
                    print "                    Encryption key:%s" % (key_status, )
                    if len(ap.rate) > 0:
                        for rate_list in ap.rate:
                            # calc how many full lines of bitrates
                            rate_lines = len(rate_list) / 5
                            # calc how many bitrates on last line
                            rate_remainder = len(rate_list) % 5
                            line = 0
                            # first line should start with a label
                            rate_line = "                    Bit Rates:"
                            while line < rate_lines:
                                # print full lines
                                if line > 0:
                                    # non-first lines should start *very* indented
                                    rate_line = "                              "
                                rate_line = rate_line + "%s; %s; %s; %s; %s" % \
                                    tuple(wifi._formatBitrate(x) for x in
                                        rate_list[line * 5:(line * 5) + 5])
                                line = line + 1
                                print rate_line
                            if line > 0:
                                # non-first lines should start *very* indented
                                rate_line = "                              "
                            # print non-full line
                            print rate_line + "%s; "*(rate_remainder - 1) % \
                                tuple(wifi._formatBitrate(x) for x in
                                    rate_list[line * 5:line * 5 + rate_remainder - 1]) + \
                                "%s" % (wifi._formatBitrate(
                                        rate_list[line * 5 + rate_remainder - 1]))
                    index = index + 1
            print
</pre>
 

<span style="color: #808000;">若說條條大路通羅馬。事物總有交會處,事理經常能互補。何不就盡興的『玩』科技呢??方法之事或許多多益善!終會有應用之時的耶!!</span>

 

<span style="color: #ff9900;">※ 補記︰請特別注意上面那個『 sudo 』。想多了解『 iwlib 』資料結構者,或將需要『 iwlib.h 』檔案,請用</span>

<span style="color: #808080;">sudo apt-get install libiw-dev</span>

<span style="color: #ff9900;">取得。</span>

<span style="color: #808080;"><strong>【參考資料】</strong></span>
<pre class="lang:sh decode:true ">pi@raspberrypi ~

*** Error message:
Missing $ inserted.
You can't use `macro parameter character #' in vertical mode.
leading text: #
Unicode character 選 (U+9078)
leading text: # 選
Unicode character 取 (U+53D6)
leading text: # 選取
Unicode character 裝 (U+88DD)
leading text: # 選取 WiFi 裝
Unicode character 置 (U+7F6E)
leading text: # 選取 WiFi 裝置
You can't use `macro parameter character #' in vertical mode.
leading text: #
Unicode character 熱 (U+71B1)
leading text: # AP 熱
Unicode character 點 (U+9EDE)
leading text: # AP 熱點
Unicode character 掃 (U+6383)
leading text: # AP 熱點掃
Unicode character 描 (U+63CF)
leading text: # AP 熱點掃描
You can't use `macro parameter character #' in vertical mode.
leading text: #
Unicode character 探 (U+63A2)

more /usr/include/iwlib.h
/*
* Wireless Tools
*
* Jean II - HPLB 97->99 - HPL 99->09
*
* Common header for the Wireless Extension library...
*
* This file is released under the GPL license.
* Copyright (c) 1997-2009 Jean Tourrilhes <jt@hpl.hp.com>
*/

#ifndef IWLIB_H
#define IWLIB_H

/***************************** INCLUDES *****************************/

/* Standard headers */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fcntl.h>
--More--(3%)

 

 

 

 

 

 

 

 

 

勇闖新世界︰ W!o《卡夫卡村》變形祭︰圓局定向‧二

就讓我們從

python-wifi 0.6.0

Python WiFi is a Python module that provides read and write access to a wireless network card’s capabilities using the Linux Wireless Extensions.

Python WiFi is a Python module that provides read and write access to a wireless network card’s capabilities using the Linux Wireless Extensions. It was initially developed by Roman Joost with advice from Guido Goldstein of Infrae. It is currently maintained by Sean Robinson.……

 

的安裝開始,

wget http://git.tuxfamily.org/pythonwifi/pythonwifi.git/snapshot/pythonwifi-0.6.0.tar.gz
tar zxvf pythonwifi-0.6.0.tar.gz
cd pythonwifi-0.6.0/
sudo python setup.py install

※ 註記︰因為萬國碼的相容性問題,目前 pythonwifi 只能用於派生二,不能用於派生三。

進入

Python WiFi

A new api is being organized for Python WiFi beyond v0.6.0. Your feedback will make Python WiFi better, so please participate. Join the mailing list and join the discussion.

Python WiFi is intended for developers that wish to use their WiFi card from within a Python program. If you are looking for a GNU/Linux program to scan for, and connect with, WiFi networks, you may want to try WiFi Radar, Wicd, or NetworkManager.

Python WiFi is a Python module that provides read and write access to a wireless network card’s capabilities using the Linux Wireless Extensions. This module was initially created by Róman Joost and is currently maintained by Sean Robinson <robinson@tuxfamily.org>. The latest version is 0.6.0.

Documentation

Matrices of features to try to match: Wireless Extensions, iwconfig.py, and iwlist.py.

Source Code

Browse the Source

Download

A Python source package is available at the Python Package Index.

“Python” and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used with permission.

Last Update: March 23, 2015

 

派生 WiFi 程式之域。然而這個程式庫的說明文件僅有兩個範例,將要如何學習的呢?固然閱讀原始碼是一種方法,通常耗時得慢活,一般乃必要才為之之事。幸好大部份『派生程式庫』的作者喜歡『吉多』 Guido 大教主倡導的『 Code Style 』編碼風格,於是我們可以嘗試『help □○』,

pi@raspberrypi ~ 
*** QuickLaTeX cannot compile formula:
python
Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pythonwifi.iwlibs import Wireless
>>> wifi = Wireless('eth1')
>>> help(wifi)
</pre>
<span style="color: #808000;">結果得到</span>

<span style="color: #808080;">Help on Wireless in module <span style="color: #ff9900;">pythonwifi.iwlibs</span> object:</span>

<span style="color: #808080;">class <span style="color: #ff9900;">Wireless</span>(__builtin__.object)</span>
<span style="color: #808080;"> | Provides high-level access to wireless interfaces.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | This class uses <span style="color: #ff9900;">WirelessInfo</span> for most access.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | Methods defined here:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | __init__(self, ifname)</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | commit(self)</span>
<span style="color: #808080;"> | Commit pending changes.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getAPaddr</span>(self)</span>
<span style="color: #808080;"> | Returns the access point MAC address.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless, getNICnames</span>
<span style="color: #808080;"> | >>> ifnames = getNICnames()</span>
<span style="color: #808080;"> | >>> ifnames</span>
<span style="color: #808080;"> | ['eth1', 'wifi0']</span>
<span style="color: #808080;"> | >>> wifi = Wireless(ifnames[0])</span>
<span style="color: #808080;"> | >>> wifi.getAPaddr()</span>
<span style="color: #808080;"> | '00:0D:88:8E:4E:93'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | Test with non-wifi card:</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth0')</span>
<span style="color: #808080;"> | >>> wifi.getAPaddr()</span>
<span style="color: #808080;"> | (95, 'Operation not supported')</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | Test with non-existant card:</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth2')</span>
<span style="color: #808080;"> | >>> wifi.getAPaddr()</span>
<span style="color: #808080;"> | (19, 'No such device')</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getBitrate</span>(self)</span>
<span style="color: #808080;"> | Returns the device's currently set bit rate in Mbit.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getBitrate()</span>
<span style="color: #808080;"> | '11 Mb/s'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> |<span style="color: #ff9900;"> getBitrates</span>(self)</span>
<span style="color: #808080;"> | Returns the number of bitrates available for the device.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> num, rates = wifi.getBitrates()</span>
<span style="color: #808080;"> | >>> num == len(rates)</span>
<span style="color: #808080;"> | True</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getChannelInfo</span>(self)</span>
<span style="color: #808080;"> | Returns the number of channels and available frequencies for</span>
<span style="color: #808080;"> | the device.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> num, rates = wifi.getChannelInfo()</span>
<span style="color: #808080;"> | >>> num == len(rates)</span>
<span style="color: #808080;"> | True</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getEncryption</span>(self)</span>
<span style="color: #808080;"> | Get the association mode, which is probably a string of '*',</span>
<span style="color: #808080;"> | 'open', 'private', 'off'.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | As a normal user, you will get an 'Operation not permitted'</span>
<span style="color: #808080;"> | error:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getEncryption()</span>
<span style="color: #808080;"> | (1, 'Operation not permitted')</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> |<span style="color: #ff9900;"> getEssid</span>(self)</span>
<span style="color: #808080;"> | Returns the current ESSID information.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getEssid()</span>
<span style="color: #808080;"> | 'romanofski'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getFragmentation</span>(self)</span>
<span style="color: #808080;"> | Returns the fragmentation threshold.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | It depends on what the driver says. If you have fragmentation</span>
<span style="color: #808080;"> | threshold turned on, you'll get an int. If it's turned off</span>
<span style="color: #808080;"> | you'll get a string: 'off'.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getFragmentation()</span>
<span style="color: #808080;"> | 'off'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getFrequency</span>(self)</span>
<span style="color: #808080;"> | Returns currently set frequency of the card.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getFrequency()</span>
<span style="color: #808080;"> | '2.417 GHz'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getKey</span>(self, key=0, formatted=True)</span>
<span style="color: #808080;"> | Get an encryption key.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | key 0 is current key, otherwise, retrieve specific key (1-4)</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | As a normal user, you will get an 'Operation not permitted'</span>
<span style="color: #808080;"> | error:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getKey()</span>
<span style="color: #808080;"> | ABCD-9512-34</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getKeys</span>(self)</span>
<span style="color: #808080;"> | Get all encryption keys.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | Returns a list of tuples.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | As a normal user, you will get a 'Operation not permitted'</span>
<span style="color: #808080;"> | error:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getKeys()</span>
<span style="color: #808080;"> | [(1, '1234-5678-91'), (2, None), (3, 'ABCD-EFAB-CD'), (4, None)]</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getMode</span>(self)</span>
<span style="color: #808080;"> | Returns currently set operation mode.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getMode()</span>
<span style="color: #808080;"> | 'Managed'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getPowermanagement</span>(self)</span>
<span style="color: #808080;"> | Returns the power management settings.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | #>>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | #>>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | #>>> wifi.getPowermanagement()</span>
<span style="color: #808080;"> | #'off'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getQualityAvg</span>(self)</span>
<span style="color: #808080;"> | Returns an Iwquality object with average quality information.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> aq = wifi.getQualityAvg()</span>
<span style="color: #808080;"> | >>> print "quality:", aq.quality, "signal:", aq.siglevel, "noise:", aq.nlevel</span>
<span style="color: #808080;"> | quality: 38 signal: 13 noise: 0</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getQualityMax</span>(self)</span>
<span style="color: #808080;"> | Returns an Iwquality object with maximum quality information.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> mq = wifi.getQualityMax()</span>
<span style="color: #808080;"> | >>> print "quality:", mq.quality, "signal:", mq.siglevel, "noise:", mq.nlevel</span>
<span style="color: #808080;"> | quality: 38 signal: 13 noise: 0</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getRTS</span>(self)</span>
<span style="color: #808080;"> | Returns the RTS threshold, likely to be int, 'auto',</span>
<span style="color: #808080;"> | 'fixed', 'off'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | man iwconfig:</span>
<span style="color: #808080;"> | "RTS/CTS adds a handshake before each packet transmission to</span>
<span style="color: #808080;"> | make sure that the channel is clear. This adds overhead, but</span>
<span style="color: #808080;"> | increases performance in case of hidden nodes or a large</span>
<span style="color: #808080;"> | number of active nodes. This parameter sets the size of the</span>
<span style="color: #808080;"> | smallest packet for which the node sends RTS; a value equal</span>
<span style="color: #808080;"> | to the maximum packet size disable the mechanism."</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getRTS()</span>
<span style="color: #808080;"> | 'off'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getRetrylimit</span>(self)</span>
<span style="color: #808080;"> | Returns the retry/lifetime limit.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | man iwconfig:</span>
<span style="color: #808080;"> | "Most cards have MAC retransmissions, and some allow to set</span>
<span style="color: #808080;"> | the behaviour of the retry mechanism."</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getRetrylimit()</span>
<span style="color: #808080;"> | 16</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getSensitivity</span>(self)</span>
<span style="color: #808080;"> | Returns sensitivity information.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | man iwconfig:</span>
<span style="color: #808080;"> | "This is the lowest signal level for which the hardware</span>
<span style="color: #808080;"> | attempt packet reception, signals weaker than this are</span>
<span style="color: #808080;"> | ignored. This is used to avoid receiving background noise,</span>
<span style="color: #808080;"> | so you should set it according to the average noise</span>
<span style="color: #808080;"> | level. Positive values are assumed to be the raw value used</span>
<span style="color: #808080;"> | by the hardware or a percentage, negative values are</span>
<span style="color: #808080;"> | assumed to be dBm."</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getSensitivity()</span>
<span style="color: #808080;"> | 'off'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getStatistics</span>(self)</span>
<span style="color: #808080;"> | Returns statistics information which can also be found in</span>
<span style="color: #808080;"> | /proc/net/wireless.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getTXPower</span>(self)</span>
<span style="color: #808080;"> | Returns the transmit power in dBm.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getTXPower()</span>
<span style="color: #808080;"> | '17 dBm'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">getWirelessName</span>(self)</span>
<span style="color: #808080;"> | Returns the wireless name.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getWirelessName()</span>
<span style="color: #808080;"> | 'IEEE 802.11-DS'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">scan</span>(self)</span>
<span style="color: #808080;"> | Returns Iwscanresult objects, after a successful scan.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setAPaddr</span>(self, addr)</span>
<span style="color: #808080;"> | Sets the access point MAC address.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | translated from iwconfig.c</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | FIXME: This needs to check address type before acting.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setEncryption</span>(self, mode)</span>
<span style="color: #808080;"> | Set the association mode.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | As a normal user, you will get an 'Operation not permitted'</span>
<span style="color: #808080;"> | error:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.setEncryption()</span>
<span style="color: #808080;"> | (1, 'Operation not permitted')</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setEssid</span>(self, essid)</span>
<span style="color: #808080;"> | Sets the ESSID.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.getEssid()</span>
<span style="color: #808080;"> | 'romanofski'</span>
<span style="color: #808080;"> | >>> wifi.setEssid('Joost')</span>
<span style="color: #808080;"> | >>> wifi.getEssid()</span>
<span style="color: #808080;"> | 'Joost'</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setFrequency</span>(self, freq)</span>
<span style="color: #808080;"> | Sets the frequency on the card.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | translated from iwconfig.c</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setKey</span>(self, key, index=1)</span>
<span style="color: #808080;"> | Set an encryption key.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | As a normal user, you will get an 'Operation not permitted'</span>
<span style="color: #808080;"> | error:</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | >>> from iwlibs import Wireless</span>
<span style="color: #808080;"> | >>> wifi = Wireless('eth1')</span>
<span style="color: #808080;"> | >>> wifi.setKey()</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | <span style="color: #ff9900;">setMode</span>(self, mode)</span>
<span style="color: #808080;"> | Sets the operation mode.</span>
<span style="color: #808080;"> |</span>
<span style="color: #808080;"> | ----------------------------------------------------------------------</span>

 

<span style="color: #808000;">再輔之以派生『內省』之『 <span style="color: #ff9900;"><a style="color: #ff9900;" href="https://docs.python.org/3/library/inspect.html">inspect</a></span> 』視察之法,如是就能試行,</span>
<pre class="lang:sh decode:true">pi@raspberrypi ~

*** Error message:
You can't use `macro parameter character #' in math mode.
leading text: <span style="color: #
Unicode character 結 (U+7D50)
leading text: <span style="color: #808000;">結
Unicode character 果 (U+679C)
leading text: <span style="color: #808000;">結果
Unicode character 得 (U+5F97)
leading text: <span style="color: #808000;">結果得
Unicode character 到 (U+5230)
leading text: <span style="color: #808000;">結果得到
Missing $ inserted.
You can't use `macro parameter character #' in horizontal mode.
leading text: <span style="color: #
You can't use `macro parameter character #' in horizontal mode.
leading text: ...n Wireless in module <span style="color: #
You can't use `macro parameter character #' in horizontal mode.
leading text: <span style="color: #

python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pythonwifi.iwlibs import Wireless
>>> wifi = Wireless('wlan0')
>>> dir(wifi)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_formatBitrate', '_formatFrequency', 'commit', 'getAPaddr', 'getBitrate', 'getBitrates', 'getChannelInfo', 'getEncryption', 'getEssid', 'getFragmentation', 'getFrequency', 'getKey', 'getKeys', 'getMode', 'getPowermanagement', 'getQualityAvg', 'getQualityMax', 'getRTS', 'getRetrylimit', 'getSensitivity', 'getStatistics', 'getTXPower', 'getWirelessName', 'ifname', 'iwstruct', 'scan', 'setAPaddr', 'setEncryption', 'setEssid', 'setFrequency', 'setKey', 'setMode', 'sockfd', 'wireless_info']
>>> wifi.getQualityAvg()
<pythonwifi.iwlibs.Iwquality object at 0x767fd110>
>>> dir(wifi.getQualityAvg())
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'fmt', 'getNoiselevel', 'getSignallevel', 'nlevel', 'noiselevel', 'parse', 'quality', 'setNoiselevel', 'setSignallevel', 'setValues', 'siglevel', 'signallevel', 'updated']
>>> wifi.getQualityAvg().getSignallevel()
178
>>> wifi.getQualityAvg().getNoiselevel()
0

 

這就是 Python 之『非同的禪!!』,『派生大道』 Pythonic Way 的中心主旨也。

 

 

 

 

 

 

 

勇闖新世界︰ W!o《卡夫卡村》變形祭︰圓局定向‧一

雖然不知 M♪o 所用的『無線阡陌網』科技如何?就讓我們用常見的『熱點』與 USB WiFi 『小玩意』來研究那『定向器』可以怎樣實現的呢??在一篇名為

Testing of location systems using WiFi in indoor environments

的文章裡,有人探討了這個技術。更有一本叫做

Principles of Wireless Access and Localization

的書,較詳細說明了無限 WiFi 之 WPS 定位技術。

其中一個關鍵之處就在『接收訊號強度指示』 RSSI 這個『術語』。據維基百科解釋︰

Received signal strength indication

RSSI in 802.11 implementations

In an IEEE 802.11 system, RSSI is the relative received signal strength in a wireless environment, in arbitrary units. RSSI is an indication of the power level being received by the antenna. Therefore, the higher the RSSI number, the stronger the signal.

RSSI can be used internally in a wireless networking card to determine when the amount of radio energy in the channel is below a certain threshold at which point the network card is clear to send (CTS). Once the card is clear to send, a packet of information can be sent. The end-user will likely observe a RSSI value when measuring the signal strength of a wireless network through the use of a wireless network monitoring tool like Wireshark, Kismet or Inssider. As an example, Cisco Systems cards have a RSSI_Max value of 100 and will report 101 different power levels, where the RSSI value is 0 to 100. Another popular Wi-Fi chipset is made by Atheros. An Atheros based card will return an RSSI value of 0 to 127 (0x7f) with 128 (0x80) indicating an invalid value.

There is no standardized relationship of any particular physical parameter to the RSSI reading. The 802.11 standard does not define any relationship between RSSI value and power level in mW or dBm. Vendors and chipset makers provide their own accuracy, granularity, and range for the actual power (measured as mW or dBm) and their range of RSSI values (from 0 to RSSI_Max).[2] One subtlety of the 802.11 RSSI metric comes from how it is sampled—RSSI is acquired during only the preamble stage of receiving an 802.11 frame, not over the full frame. As early as 2000, researchers were able to use RSSI for coarse-grained location estimates.[3] More recent work was able to reproduce these results using more advanced techniques.[4] Nevertheless, RSSI doesn’t always provide measurements that are sufficiently accurate to properly determine the location.[5]

 

可知它不是像『尺』一般的『量距離』設備,比較像海邊『燈塔』一樣的『遠近』指示。所以實務上 WPS 常和 GPS 組在一塊,用以收集、定位、校正那些『WiFi AP』的數據。在此引用前面網文裡的兩張圖,或可意會 RSSI 與距離的複雜關係。

 

figure-8

 

figure9

 

假使在樹莓派已有 USB WiFi 『小玩意』,而且連接到 WiFi AP 上,一個『 iwconfig 』指令,可以告知『連接品質』 Link Quality 以及『訊號準位』 Signal level 。

pi@raspberrypi ~ iwconfig wlan0 wlan0     IEEE 802.11bg  ESSID:"caseyhome"  Nickname:"<WIFI@REALTEK>"           Mode:Managed  Frequency:2.412 GHz  Access Point: 10:6F:3F:62:2C:15              Bit Rate:54 Mb/s   Sensitivity:0/0             Retry:off   RTS thr:off   Fragment thr:off           Power Management:off           Link Quality=100/100  Signal level=100/100  Noise level=0/100           Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0           Tx excessive retries:0  Invalid misc:0   Missed beacon:0  pi@raspberrypi ~ 

 

另一個『 iwlist wlan0 scanning 』之指令,則能提供周遭可連線之 WiFi AP 的『連接品質』與『訊號準位』數據。這兩個指令來自於 Jean Tourrilhes 先生啟始的

Wireless Tools for Linux

Presentation

The Linux Wireless Extension and the Wireless Tools are an Open Source project sponsored by Hewlett Packard (through my contribution) since 1996, and build with the contribution of many Linux users all over the world.

The Wireless Extension (WE) is a generic API allowing a driver to expose to the user space configuration and statistics specific to common Wireless LANs. The beauty of it is that a single set of tool can support all the variations of Wireless LANs, regardless of their type (as long as the driver support Wireless Extension). Another advantage is these parameters may be changed on the fly without restarting the driver (or Linux).

The Wireless Tools (WT) is a set of tools allowing to manipulate the Wireless Extensions. They use a textual interface and are rather crude, but aim to support the full Wireless Extension. There are many other tools you can use with Wireless Extensions, however Wireless Tools is the reference implementation.

  • iwconfig manipulate the basic wireless parameters
  • iwlist allow to initiate scanning and list frequencies, bit-rates, encryption keys…
  • iwspy allow to get per node link quality
  • iwpriv allow to manipulate the Wireless Extensions specific to a driver (private)
  • ifrename allow to name interfaces based on various static criteria

Most Linux distributions also have integrated Wireless Extensions support in their networking initialisation scripts, for easier boot-time configuration of wireless interfaces. They also include Wireless Tools as part of their standard packages.

Wireless configuration can also be done using the Hotplug or uDev scripts and distribution specific support, this enable the proper support of any removable wireless interface (Pcmcia, CardBus, USB…).

Any versions of the Pcmcia package offer the possibility to do wireless configuration of Pcmcia and Cardbus card through thefile wireless.opts. This allow to fully integrate wireless settings in the Pcmcia scheme mechansism. However, this method is now deprecated in favor of distribution specific methods.

Please note that the Wireless Tools (starting with version 19) supports fully IEEE 802.11 parameters and devices, support older style of devices and most proprietary protocols, and are prepared to handle HiperLan as well. More recent versions of course adds more 802.11 support.
But, unfortunately not all drivers support all these features…

………

雖然根據

User Tools

About iw

iw is a new nl80211 based CLI configuration utility for wireless devices. It supports all new drivers that have been added to the kernel recently. The old tool iwconfing, which uses Wireless Extensions interface, is deprecated and it’s strongly recommended to switch to iw and nl80211.

Like rest of Linux kernel, iw is still under development. Features are added ‘as we go’. The only documentation for iw is this page and output from ‘iw help’. Please help expand this page.

There is a page listing use cases with iwconfig and iw: replacing iwconfig.

Getting iw

Release tarballs of iw are available from http://kernel.org/pub/software/network/iw/.

Alternatively, you can download iw from git: http://git.kernel.org/?p=linux/kernel/git/jberg/iw.git.

Build requirements

  • libnl >= libnl1
  • libnl-dev >= libnl-dev-1
  • pkg-config Using iw requires you to have libnl, the first working version is 1.0 pre8 as this release introduced genl, Generic Netlink, which nl80211 relies on. If your distribution’s libnl is a wrong version then you’ll have to download and compile libnl yourself for now (http://www.infradead.org/~tgr/libnl/).

 

所言『 Wireless Extension 』終逐步步入歷史,這個替換過程或許還很長。何不就通熟兩者的呢!接續的文本,將以『派生』方便性與『實務』容易性為考量,應用兩套工具,或有『取巧之嫌』,豈可不辯之以學習『簡易是尚』的耶!!

 

 

 

 

 

 

 

 

 

 

勇闖新世界︰ W!o《卡夫卡村》變形祭︰ ○ 局 □ 陣【☲】

既不知如何入夢?又不曉如何清醒!只覺得腦海中有個聲音在說︰入口到了。方見好大一片林子,宛如沒有盡頭一般。正疑惑著, 祇聽到 W!o^{+} 講︰這片林子和另一片林子是一雙的,在地原鄉人傳言,都是不知幾千年之前就有的古林。眼前這個圓的,古音讀若『圓局』,內有他處皆無的『蘿荔』之樹。這『蘿荔』說也奇怪,不但性喜『三五成群』,圍若圓狀,而且不時或合小圓組大圓,或散大圈為小圈,原鄉人稱之為『嫁娶』,說是『風媒』之故。由於此地四季季風不斷,而且『蘿荔』之樹之生滅快速,遂成了天造的『迷宮』一般。林徑廣十里,綠葉閉雲日,實難行也。剛想問︰… , W!o^{+} 又講︰我知你想說︰拿個『指北針』不就好了?又能有何難行之處。殊不知這『蘿荔』之樹,或因此處的水土特殊,都帶有生物磁性,那『指北針』更本不管用。根據『未公開研究』,正是這個『磁性』決定了『嫁娶』方向的呢!?也許造林子的古人刻意如此,所以建有『九石台』,誰知卻種下了,後人『九石台』之辯。這『九石台』乃依洛書方位,八座小居圓周之上,一座大在林中央。台邊土據方位五行之色,周遭『蘿荔』不生。考察發現那台石能夠導電且深入地層,今人以為是『地熱電池』。後來 M♪o 在台上建置了『無線阡陌網』之『定向器』,方便谷內之人的進出。由於事涉保安,不便多言,況且可逛之處太多,祭典不遠,就趕路的吧!!……

此『無線阡陌網』之『定向器』將要如何比之擬之的哩?苦思冥想之後,或可比擬為『WPS』的耶??維基百科說︰

Wi-Fi positioning system

Wi-Fi-based positioning system (WPS) or WiPS/WFPS is used where GPS is inadequate due to various causes including multipath and signal blockage indoors. Such systems include indoor positioning systems. Wi-Fi positioning takes advantage of the rapid growth in the early 21st century of wireless access points in urban areas.

The localization technique used for positioning with wireless access points is based on measuring the intensity of the received signal (received signal strength or RSS) and the method of “fingerprinting”.[1][2] Typical parameters useful to geolocate the Wi-Fi hotspot or wireless access point include the SSID and the MAC address of the access point. The accuracy depends on the number of positions that have been entered into the database. The Wi-Fi hotspot database gets filled by correlating mobile device GPS location data with Wi-Fi hotspot MAC addresses.[3] The possible signal fluctuations that may occur can increase errors and inaccuracies in the path of the user. To minimize fluctuations in the received signal, there are certain techniques that can be applied to filter the noise.

In the case of low precision, some techniques have been proposed to merge the Wi-Fi traces with other data sources such as geographical information and time constraints (i.e., time geography).[4]

 

因為網路科技博大精深,難以筆墨形容,況且更兼實務描述困難,不得不採系統『疊套想象』之法,補之以剝洋蔥『層層分解』之術 ,以期方便讀者閱讀。特舉範例文本如下︰

咬一口 TCPIP!!上》───

internet1

清代  歸莊觀田家收獲
稻香秫熟暮秋天,
阡陌縱橫萬畝連。
五載輸糧女真國,
天全我誌獨無田。

中醫觀象上說︰入於處之小腸趨於居之,…;講的是四季頤養之道依時進補之法。或許網路道荼蓼一文,可與之相通;所謂荼蓼目之 ☲,坤地之 ☷, 自然能得離日耀目出地中天的 ☲ ☷ 卦之進取之境,所以才倒吃甘蔗

俗話說『民以食為天』,今日不吃『英特乃』大概不能活了!!頭上既有青天白雲,腳底常陪綠地嫩草,奈何伊只顧低頭一指觸知天下事?一個奇想帶來的蝴蝶效應,豈只驚天動地,簡直併吞地球,不過英特乃是否真源自『地球村』之『桃花源』尚待『考證』。之前講了『其人其事』,現在就談談『其物』──  乙太網 ──吧。人們一般以為乙太網發明於 1973 年,其因在於 Robert Melancton “BobMetcalfe 工作於全錄 PARC 時,受到 ALOHA 網路架構的啟發 ,寫了一張給他老闆有關乙太網潛力備忘錄。但是梅特卡夫自己卻認為乙太網是其後幾年才出現的,至少應該說是在 1976 年和他的助手David Boggs 發表了一篇名為《乙太網:區域網路的分封交換技術 》的文章之後。不論早三年還是晚三年,大體與 ARPA 網之父時期相當;作者試著簡化長篇歷史,假借卦象比之擬之的對比祈能易懂易讀。

澤風大過 ☱ ☴根莖葉網際網路
上六,過涉滅頂,
凶,旡咎。
一套網際網路規範
Internet Protocol Suite
九五,枯楊生華,
老婦得其士夫,旡咎旡譽。
應用層
Application Layer
九四,棟隆,
吉,有它吝。
傳送層
Transport Layer
九三,棟橈,
凶。
網際網路層
Internet Layer
九二,枯楊生稊,
老夫得其女妻,旡不利。
網路存取層
Network Access Layer
初六,藉用白茅,
旡咎。
實體層
Physical

───

 

吃一節 TCPIP!!中》───

240px-Möbius_strip

220px-Trefoil_knot_arb

MobiusStrip-01

拓撲學 Topology 一詞源自希臘文『地點之研究』,始於歐拉柯尼斯堡的七橋問題。這門數學探討連通性 connectedness 、連續性 continuity 、以及邊界 boundary。它不用東西的『形狀』來作分類,而是分析那個東西裡所有連通的點,各個連續的區域,和有哪些分別內外的邊界。想畫德國數學家莫比烏斯發現的帶子  Möbius strips ,它只有一個『』和一條『邊界』?!

Möbius strips

220px-BusNetwork.svg

220px-Network_card

500px-Coaxial_cable_cutaway.svg

lans.bus

220px-StarNetwork.svg

剛開始乙太網是用一條『同軸電纜』當作信號訊息傳送的骨幹,它的網路拓撲就像一個『』字,稱之為匯流排 BUS,是個運『信號波』的公車站。由於每一個連接到 BUS 的節點 = 接點 NODE,都可用作『收發』點,那就必須考慮對應的通訊機制。當然一個節點發送每個接點都同時接收沒有什麼問題;然而多個節點同時發送,就會產生信號『碰撞』以致訊息錯誤。這些特性的總稱叫做 CSMA/CD ── CS = 載波偵聽、MA=多路存取和CD=碰撞察覺 ──,可以說 BUS 上廣告著 ALOHA 在這裡!

由於任一節點的收發都是連通的自己發送自己也可以接收,這稱為 loopback 回送;在 Raspbian 裡,就是你用 ifconfig 命令看到的 lo ,它的 IP 地址通常是 127.0.0.1 ,這是 IPv4 所保留的 256 個地址區塊 127.0.0.0/8 ── 127.0.0.0 到127.0.0.255 ──之一。其次任一個節點都可以接收所有其它接點的信號,不管是不是發送給它的;通常乙太網卡驅動程式過濾掉這些不是自己應該接收的訊息,但是你也可以進入所謂混雜模式 Promiscuous mode 去監聽所有的收發。再者,乙太網使用自己全球唯一的 48 位元 MAC 媒介存取控制位址,約為二百八十兆個地址來區別連上它的整個世界不同的節點。不知是夠是不夠??

碰撞察覺的載波偵聽多路存取 CSMA/CD 技術要如何實現通訊機制呢?藉著節點收發守則

一、開始發送前── 偵聽到線路空閒才啟動傳輸,否則移至第四步

二、發送──即使察覺碰撞,繼續發送一段最小的時距,用以確保 所有其它節點都能察覺碰撞,再移至第四步

三、發送成功──回報上層的網路協定傳送成功,結束發送模式。

四、忙線中──等待,直至偵聽到線路空閒

五、擲骰子──線路雖已進入空閒狀態 ,必須等待隨機的一段時間,才可移至第一步,假如超過約定的最大嘗試次數,就走下一步吧

六、失敗── 回報上層的網路協定傳送失敗,結束發送模式

咦!說的不是收發守則嗎?怎們沒講到『接收』呢?節點總是接收的,就像耳朵聽的到自己說話一樣;更何況以對談的目的而言,一大半都是聽別人講話,所以講的人需要懂得『禮貌』,如果大家『搶著說』那就一團混亂了。哦!愛因斯坦不是說『上帝不擲骰子』嗎?為什麼要擲骰子呢?由於『等待多久』是很難決定的,所以才把它交給能確定『隨機』的上帝!!

───

 

啃一塊唄 K TCPIP!!下》───

金文回

金文串

220px-Screenshot_Recursion_via_vlc

TCPIP規範之堆疊 Stack 看起來什麼呢?俯察個『』字,側寫個『』文。不論它看起來像個什麼或有沒有形狀,它是網路主宰,也是通往英特乃大道老子第二十五章裡說︰
有物混成,天地兮,獨立不改周行不殆可以为天地。吾不知其名字之为之曰:。大曰,逝曰,遠曰

回文都能讀通的句子,有人說它源自『道德经』,故稱之為『道原』︰
第二十章 ── 俗人昭昭,我獨昏昏,俗人察察,我獨悶悶。
六十三章 ── 為无為,事无事,味无味。
八十一章 ── 信言不美,美言不信。

苏伯玉妻盘中诗

苏伯玉妻

可以清心也

那視之成串回文字之道原可有一個『讀法』?有人不止能讀還能寫,話說蘇伯玉赴蜀日久未歸,其妻獨居長安,七巧心思制作相思盤,探盼其夫心中是否有個她?

漢代 蘇伯玉盤中詩
山樹高,鳥鳴悲。泉水深,鯉魚肥。
空倉雀,常苦飢。吏人婦,會夫稀。
出門望,見白衣。謂當是,而更非。
還入門,中心悲。北上堂,西入階。
急機絞,杼聲催。長嘆息,當語誰。
君有行,妾念之。出有日,還無期。
結中帶,長相思。君忘妾,天知之。
妾忘君,罪當治。妾有行,宜知之。
黃者金,白者玉。高者山,下者谷。
姓者蘇,字伯玉,作人才多智謀足。
家居長安身在蜀,何惜馬蹄歸不數。
羊肉千斤酒百斛,令君馬肥麥與粟。
今時人智不足與其書不能讀
當從中央周四角

作者不知蘇伯玉歸是不歸?一杯『可以清心也』之己能『千回百轉』,解者自能消酷暑之永晝!!

說道這個規範堆疊分解的說也許可以圖示如下︰

TCP-IP-STACK

上圖各色分明左說右講程式所中道其事

精讀細思后,設想作這樣『一個包裹著另一個』的事有什麼好處呢?其實這就是就層層對應中之某層而言『上中下』相關的譯解結構在上目的語言為在『其中』者分割譯解在下手段控制。這使得越往上技術細節將被越多層所包裹不必知其詳,所以網際網路應用軟體的人,通常知道 TCP/IP 界面的 API 用法就夠了,很少直接用到乙太網的實體層界面。當然愈向下的技術細節也就愈多,也許有時發生的『狀況』超出程式的預期時會很有用。在此將它綜合成一個表解吧︰

彼接點信號之發送↑↓←→
層對層
上語下
列言列
↓↑→←
列知列
下道上
層應層
此節點訊息之接收
彼上上‧目的此上上‧目的
彼上‧目的語言此上‧目的語言
轉譯彼上之目的
話成彼下之手段
←→
堆言疊語
彼文此解
←→
疊語堆言
此字彼譯
轉翻此上之目的
說解此下之手段
彼下‧手段文字此下‧手段文字
彼下下‧手段此下下‧手段

───

 

 

 

 

 

 

 

 

輕。鬆。學。部落客