2012年8月29日 星期三

SubnetMask計算


[MIS] 計算SubnetMask

一.為何要使用subnet mask


在IPv4的協定下,IP位址是由4個8位元組成的數字來表達,如200.1.1.130。

一個IP位址分為網路位址(Network Address)+主機位址(Host Address),依網路位址所佔的位元數不同而分為A/B/C/D級網路。

IP數字的0及255是預設的主機及廣播位址無法使用,所以每個數字可用的IP位址變化只有254個(256-2),這也就是一般C級網段的Gateway IP都預設x.x.x.254的緣故。

IPv4的位址因為ABCD型網段的配法而無法完全應用到254四次方那樣多的可用IP值,隨著世界上主機數遞增,IP位址漸漸不夠用了!在IPv6的應用尚未完全普及之時,就得利用切分子網路(Subnet)的方式來有效分配IP位址。

將同一個IP位址等級的網路再切割成數個子網路,如此網路規模較小,避免降低網路效能。

切割後的子網路可正常與其他網路互相連接。

二.如何計算 subnet mask
某台網路主機,它的IP及子網路表示法為200.1.1.130/28,從這樣簡短的字句,你該立刻看出什麼呢?

1.子網路的遮罩位址為何?
該數字28是代表遮罩IP位址的網路位址所佔位元數,即:11111111.11111111.11111111.11110000,遮罩位元為1者是讓IP通過(合法),0者為阻擋,所以從上述的32位元分布,我們得知它的網段型態是屬於C型位址,因此十進位的遮罩位址就是255.255.255.240(只需要求算右邊那四個1),即 128 + 64 + 32 + 16 = 240

2.可切成幾個子網路?
數字1是讓IP通過,所以只要注意1的位元變化組合(因為後面的0怎麼變化都會被擋住),(1111)= 2^4 = 16,共有16種變化。

3.每個子網段有幾個IP值?
子網路ip數為 256/16 = 16 (有效IP為14,因為頭尾IP要去除)

4.每個子網路的IP起迄位址?
200.1.1.0-15,200.1.1.16-31,200.1.1.32-48,...,200.1.1.240-255
例如,主機IP為200.1.1.130/28的所在子網路起迄IP為: 130/16 = 8, 16 * 8 = 128,故在 200.1.1.128-143媕Y。

假如上述你都了解的話,讓我們反過來思考,用子網路IP起迄位址,反推出它的IP/Subnet表達格式?例如,我們要讓某C級網段(192.83.184.*)下的IP合法通過,這組子網路該怎麼用IP/Subnet格式表示呢?

首先,第四個IP值不遮封,因此遮罩IP位址的2進位是: 11111111.11111111.11111111.00000000 (255.255.255.0),其網路位址位元數共24個,因此寫法是: 192.83.184.0/24,依此類推,B級網段就是192.84.0.0/16,全部開放就是: 0.0.0.0/0。所以,從IP位址的二進位表示法的位元分布,就可看出其背後的隱藏資訊,只要您能了解這些概念就可直接看出來,不需再作IP(192.83.184.0)轉二進位的運算(江湖一點訣)。

三.結論
(結論的部份,是我自己綜合網路上關於子網路遮罩教學的文章,自己歸納出來的簡單算法,不曉得是不是真的完全適用,歡迎指教!)
如果要從IP資料反推出 subnet mask 的話,只要用256減去自己所配發到的IP總數,就可以知道自己的 subnet mask 是多少 (適用於class c 的網段)
例如:
分配到的IP為 200.1.1.128-143 共 16 個 IP,那麼用 256-16 = 240 即 subnet mask 就是 255.255.255.240


參考資料:
寫得很好的範例

2012年8月27日 星期一

gpupdate /force


Microsoft Windows XP [版本 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>gpupdate /force
正在重新整理原則...

User 原則重新整理已完成。
Computer 原則重新整理已完成。


C:\Documents and Settings\Administrator>

2012年8月22日 星期三

nbtstat -A 192.168.1.8


Microsoft Windows XP [版本 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>nbtstat -A 192.168.1.8

VMware Network Adapter VMnet8:
Node IpAddress: [192.168.75.1] Scope Id: []

    Host not found.

VMware Network Adapter VMnet1:
Node IpAddress: [192.168.112.1] Scope Id: []

    Host not found.

區域連線:
Node IpAddress: [192.168.1.253] Scope Id: []

           NetBIOS Remote Machine Name Table

       Name               Type         Status
    ---------------------------------------------
    DOMINO-K2A     <00>  UNIQUE      Registered
    WORKGROUP      <00>  GROUP       Registered
    DOMINO-K2A     <20>  UNIQUE      Registered

    MAC Address = 00-26-55-AE-29-36


C:\Documents and Settings\Administrator>

2012年8月21日 星期二

xcode-關於 iOS 開發環境設定的兩三事


  1. 若是使用自己的 apple id 取得 ios developer program 則直接參考 此聯結 做設定。
  2. 若是某人已取得 ios developer program ,要讓自己也可以開發 ( 不同/或相同的電腦,作業系統裡使用不同的使用者帳號名稱 ),則按下列步驟設定 :
    • 使用已取得 ios developer program 的 apple id 到此頁面,按下 invite person ,邀請自己,按下後自己將收到邀請函,按下邀請函上面的連結之後,會開啟網頁詢問是否已有 apple id,若已有 apple id,登入過後就會發現自己的 apple id 也加入 ios developer program 了。
    • 以自己的  apple id 參考 此聯結 做後續設定。
  3. ( 尚未測試 ) 若是某人已取得 ios developer program,後來再買了一台電腦,想要在另一台電腦上也可以開發 ( 不同的電腦,作業系統裡使用相同的使用者帳號名稱 ) ,則按下列步驟設定 :
    • 至 applications > utilities >  Keychain Access 選擇左下方 ‘Keys’ 。
    • 找到具有 iOS Development Certificate 的 private key,按下右鍵 (control +左鍵) 選 export ...。最後會得到一個 (.p12) 的檔案。
    • 將檔案複製在另一台電腦並安裝之。
    • 參考 此聯結 並跳至第六項之後做後續設定。
  4. 因為 Snow Leopard 上的 xcode 只到 4.2 版就沒有再更新了,因此若手機上的 iOS 是 5.1 版,則要升級作業系統至 Lion ( 才可安裝 xcode 4.3 以上版本) 或將手機 iOS 降級至 5.0 才可讓 xcode 支援使用。若不想升級作業系統或降級 iOS,還是可以按照下列步驟將 iOS 5.1 SDK 強制安裝至 xcode 4.2 (參考 此聯結 ) :
    • 到 這裡 下載最新版 xcode。
    • 進入 terminal (applications > utilities > terminal ),依序輸入下列指令 ( 此指令是針對 xcode 4.2 安裝至 /Developer )
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1\ \(9B176\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/
sudo rm -f /Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latestcd /Developer/Platforms/iPhoneOS.platform/DeviceSupport/
sudo ln -s ./5.1\ \(9B176\) ./Latest

telnet domino port


Welcome to Microsoft Telnet Client

逸出字元是 'CTRL+]'


Microsoft Telnet> q

C:\Documents and Settings\Administrator>telnet 192.168.1.8 1352

pathping dns.hinet.net


C:\Documents and Settings\Administrator>pathping dns.hinet.net

Tracing route to dns.hinet.net [168.95.1.1]
over a maximum of 30 hops:
  0  Sigma-Tim2.sigmakao.com [192.168.1.253]
  1  192.168.1.3
  2  211-23-250-57.HINET-IP.hinet.net [211.23.250.57]
  3  172.16.1.1
  4  SKC1-3302.hinet.net [168.95.211.210]
  5  61-219-3-69.HINET-IP.hinet.net [61.219.3.69]
  6  dns.hinet.net [168.95.1.1]

Computing statistics for 150 seconds...
            Source to Here   This Node/Link
Hop  RTT    Lost/Sent = Pct  Lost/Sent = Pct  Address
  0                                           Sigma-Tim2.sigmakao.com [192.168.1
.253]
                                0/ 100 =  0%   |
  1    1ms     0/ 100 =  0%     0/ 100 =  0%  192.168.1.3
                                0/ 100 =  0%   |
  2   30ms     0/ 100 =  0%     0/ 100 =  0%  211-23-250-57.HINET-IP.hinet.net [
211.23.250.57]
                                0/ 100 =  0%   |
  3   35ms     0/ 100 =  0%     0/ 100 =  0%  172.16.1.1
                                0/ 100 =  0%   |
  4   33ms     0/ 100 =  0%     0/ 100 =  0%  SKC1-3302.hinet.net [168.95.211.21
0]
                                0/ 100 =  0%   |
  5   28ms     0/ 100 =  0%     0/ 100 =  0%  61-219-3-69.HINET-IP.hinet.net [61
.219.3.69]
                                0/ 100 =  0%   |
  6   27ms     0/ 100 =  0%     0/ 100 =  0%  dns.hinet.net [168.95.1.1]

Trace complete.

2012年7月24日 星期二

2012年6月15日 星期五

Xcode-iOS 開發環境設定


若是使用自己的 apple id 取得 ios developer program 則直接參考 此聯結 做設定。
若是某人已取得 ios developer program ,要讓自己也可以開發 ( 不同/或相同的電腦,
作業系統裡使用不同的使用者帳號名稱 ),

則按下列步驟設定 :

使用已取得 ios developer program 的 apple id 到此頁面,按下 invite person ,邀請自己,
按下後自己將收到邀請函,按下邀請函上面的連結之後,會開啟網頁詢問是否已有 apple id,
若已有 apple id,登入過後就會發現自己的 apple id 也加入 ios developer program 了。


( 尚未測試 ) 若是某人已取得 ios developer program,後來再買了一台電腦,
想要在另一台電腦上也可以開發 ( 不同的電腦,作業系統裡使用相同的使用者帳號名稱 ) ,則按下列步驟設定 :

至 applications > utilities >  Keychain Access 選擇左下方 ‘Keys’ 。
找到具有 iOS Development Certificate 的 private key,按下右鍵 (control +左鍵) 選 export ...。
最後會得到一個 (.p12) 的檔案。
將檔案複製在另一台電腦並安裝之。


因為 Snow Leopard 上的 xcode 只到 4.2 版就沒有再更新了,
因此若手機上的 iOS 是 5.1 版,則要升級作業系統至 Lion ( 才可安裝 xcode 4.3 以上版本) 或
將手機 iOS 降級至 5.0 才可讓 xcode 支援使用。若不想升級作業系統或降級 iOS,
http://forum.unity3d.com/threads/130953-Tip-Using-XCode-4.2-on-Snow-Leopard-to-test-with-iOS-5.1-devices
還是可以按照下列步驟將 iOS 5.1 SDK 強制安裝至 xcode 4.2:
https://developer.apple.com/downloads/index.action#

進入 terminal (applications > utilities > terminal ),依序輸入下列指令 ( 此指令是針對 xcode 4.2 安裝至 /Developer )
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
sudo cp -R /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1\ \(9B176\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/
sudo rm -f /Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latestcd /Developer/Platforms/iPhoneOS.platform/DeviceSupport/
sudo ln -s ./5.1\ \(9B176\) ./Latest

Xcode - Snow Leopard 使用 Xcode4.2 如何讓 IOS 5.1裝置認證過關


首先下載xcode4.3 雙擊dmg文件打開右鍵xcode圖標瀏覽裡面的內容拷貝出上面所說的文件夾過程如下:

1. 複製文件夾Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1 (9B176) 到系統文件夾Developer/Platformes/iPhoneOS.platform/DeviceSupport
2. 複製文件夾Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk 到系統文件夾Developer/Platformes/iPhoneOS.platform/Developer/SDKs
3. 複製文件家Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk 到系統文件夾Developer/Platformes/iPhoneSimulator.platform/Developer/SDKs/
4. 5. 同樣的方法把version.plist 和docsets 拷貝過去

xcode-如何將App安裝至自己的iPhone測試


在一切開始之前
首先先將你要測試的iPhone手機裝上 Ad Hoc Helper 這個程式。

這個程式可以將手機的資訊寄到你指定的Email裡,我們主要是需要抓手機的Device ID,Device ID是像這樣一串的16進位編碼字串 4f635dc13835007c3xxxxxxxfa9d4e651605f092,共有40個characters。
在Mac上建立Login Certification
1. 開啟應用程式 → 工具程式
2. 點選鑰匙圈存取 (keychain)
3. 開啟 keychain 程式後,由鑰匙圈存取 → 憑證輔助程式 → 從憑證授權要求憑證
4. 輸入你的Email及名稱,然後勾選儲存到磁碟指定密鑰配對資訊
5. 完成之後就會看到多了一個 Public Key 及 Private Key,並會在桌面上產出一個名為
CertificateSigningRequest.certSigningRequest 的檔案

建立開發用憑證及App Provision
首先連到iPhone Provision Portal頁面
1. 建立開發用憑證。點選Certificates → Development → Request Certificate
若還沒裝過WWDR憑證(Apple Worldwide Developer Relations Certification)的話,下面那個Download連結也要點。點了之後會下載一個名為 AppleWWDRCA.cer 的檔案。
註: 如果是要正式發佈到App Store,則改成點選 Distribution頁籤
2. 點取”選擇檔案”,將剛剛在Mac上利用Keychain做出來的 CertificateSigningRequest.certSigningRequest 檔匯入
3. 匯入成功之後,就會看到已經產出了一個開發者憑證了,點選Download會下載一個名為 developer_identity.cer 的檔案
4. 建立測試Device清單。點選Devices → Add Devices,輸入你想取的名字及Device ID。Device ID即要靠一開始提到的Ad Hoc Helper程式得到
5. 建立App ID。點選App IDs → New App ID,照著表格填寫即可。請注意! 一旦建立一個App ID後,將永遠不能刪掉 (不知道以後會不會開放,Apple的說法是因為他們要留下來做記錄)。所以請不要建立太多App ID以免造成自己的困擾 (像我一樣… =.,=)
6. 建立Provision Profile。點選 Provisioning → Development → New Profile。照著表格填寫即可,建好之後點選Download會下載一個名為 [Profile Name].mobileprovision 的檔案
註: 如果是要正式發佈到App Store,則改成點選 Distribution頁籤
全部的動作完成之後,總共會得到如以下三個檔(或後兩個檔)。
7. double click developer_identity.cer 檔會開啟keychain,會看到已經多了一個iPhone Development的憑證。注意到上面有個Apple Worldxxx的憑證,即是 AppleWWDRCA.cer 憑證寫入的

點選Key,會看到Private Key已經與iPhone Development憑證做關聯了
8. 將你的iPhone用傳輸線接好Mac。double click [Profile Name].mobileprovision 檔,即會開啟XCode的Organizer畫面,並將Provision安裝至iPhone裡。
9. Okay! 一切都準備完了,接下來就是開啟XCode將App Upload到你的iPhone上去囉。執行環境選擇 Device → Run! 等它跑完… 恭喜!! 你終於可以在你的iPhone上Run你的程式囉! :smile:

GridView的表頭跨欄設計


if (e.Row.RowType == DataControlRowType.Header)
{
TableCellCollection oldCell = e.Row.Cells;
oldCell.Clear();//將原有的表頭格式移除

//產生多重表列的第一列
GridViewRow headRow = new GridViewRow(0,0, DataControlRowType.Header, DataControlRowState.Insert);

//第一欄
TableCell head2Cell = new TableCell();
head2Cell.Text = "單位";
head2Cell.BackColor = row1color();//自訂的方法用以統一取得色彩
head2Cell.HorizontalAlign = HorizontalAlign.Center;
head2Cell.RowSpan = 2;//所跨的欄數
headRow.Cells.Add(head2Cell);//新增自製的儲存格


//第二欄
head2Cell = new TableCell();
head2Cell.Text = "群組";
head2Cell.BackColor = row1color();
head2Cell.ColumnSpan = 8;//所跨的欄數
head2Cell.HorizontalAlign = HorizontalAlign.Center;
headRow.Cells.Add(head2Cell);//新增自製的儲存格

//第三欄
head2Cell = new TableCell();
head2Cell.Text = "聯絡人";
head2Cell.BackColor = row1color();
head2Cell.ColumnSpan = 3;//所跨的欄數
head2Cell.HorizontalAlign = HorizontalAlign.Center;
headRow.Cells.Add(head2Cell);//新增自製的儲存格

//第四欄
head2Cell = new TableCell();
head2Cell.Text = "行事曆";
head2Cell.BackColor = row1color();
head2Cell.ColumnSpan = 3;//所跨的欄數
head2Cell.HorizontalAlign = HorizontalAlign.Center;
headRow.Cells.Add(head2Cell);//新增自製的儲存格

//將自製的資料列新增上去
GridView1.Controls[0].Controls.Add(headRow);

//產生多重表列的第二列
headRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

#region 群組裡的欄位

//用法都與第一列相同
head2Cell = new TableCell();
head2Cell.Text = "使用量";
head2Cell.BackColor = row2color();//自訂的方法用以統一取得色彩
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "成員數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "員工數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "通訊錄量";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "檔案總數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "總檔案量";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "檔案下載次數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "下載磁碟總量";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

#endregion

#region 聯絡人裡的欄位

head2Cell = new TableCell();
head2Cell.Text = "使用人數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "聯絡人數量";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "同步次數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

#endregion

#region 行事曆裡的欄位

head2Cell = new TableCell();
head2Cell.Text = "使用人數";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "events_personal";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

head2Cell = new TableCell();
head2Cell.Text = "events_group";
head2Cell.BackColor = row2color();
headRow.Cells.Add(head2Cell);

#endregion

GridView1.Controls[0].Controls.Add(headRow);