2015年6月17日 星期三

Linux NIC Binding with Cable Modem Speedtest

最近因為專案的需求又需要研究Ookla的speedtest軟體,希望測速能夠達到840Mbps。 目前只有670Mbps左右,實在是有很大的差距。
當初想說一張NIC的GE Port不夠力所以binding兩張NIC並設定Mode為0,但是發現測試Cable modem的速度,downstream卻只有130Mbps左右,真是慘不忍睹。 但是測速同一個網段的Server且用不同的測速主機驗證又速度一致,因此目前還找不出原因。 目前只知道binding與Cable Modem測速有相當的關係。

2015年5月7日 星期四

Java SNMP Package API Used

Java SNMP Package API 是一個相當容易上手的API。 但作者開發到1.4.2就沒有再往下開發了,我發現了它的timeout機制似乎部會work 如果有興趣的人可以參考作者網站:http://jsevy.com/snmp/ 我所使用的API Sample
 
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import snmp.SNMPBadValueException;
import snmp.SNMPGetException;
import snmp.SNMPObject;
import snmp.SNMPObjectIdentifier;
import snmp.SNMPOctetString;
import snmp.SNMPSequence;
import snmp.SNMPVarBindList;
import snmp.SNMPv1CommunicationInterface;

/**
 *
 * @author Derek.Li
 */
public class SnmpGet {

    public static void println(int level, String context) {
        if (level > 0) {
            return;
        }
        System.out.println(context);
    }
//    public final String itemID = "1.3.6.1.2.1.1.1.0";

    public String snmpGet(String IP, String community, String OID) {
        try {
            InetAddress hostAddress = InetAddress.getByName(IP);
            int version = 0; //設定0的時候為使用snmpv1
            SNMPv1CommunicationInterface comInterface = new SNMPv1CommunicationInterface(version, hostAddress, community);
            comInterface.setSocketTimeout(5000); //ms = 1/1000 s

            // the getMIBEntry method of the communications interface returns an SNMPVarBindList
            // object; this is essentially a Vector of SNMP (OID,value) pairs. In this case, the
            // returned Vector has just one pair inside it.
            SNMPVarBindList newVars = comInterface.getMIBEntry(OID);
            // extract the (OID,value) pair from the SNMPVarBindList; the pair is just a two-element
            // SNMPSequence
            SNMPSequence pair = (SNMPSequence) (newVars.getSNMPObjectAt(0));
            // extract the object identifier from the pair; it's the first element in the sequence
            SNMPObjectIdentifier snmpOID = (SNMPObjectIdentifier) pair.getSNMPObjectAt(0);
            // extract the corresponding value from the pair; it's the second element in the sequence
            SNMPObject snmpValue = pair.getSNMPObjectAt(1);

            // print out the String representation of the retrieved value
            String result = snmpValue.toString();
            if(OID.equals("1.3.6.1.2.1.2.2.1.6.2"))
                return ((SNMPOctetString)snmpValue).toHexString();
            return result;
        } catch (Exception e) {
            String result = null;
            return result;
        }
    }
}
   

2015年4月6日 星期一

Acronis 11 Backup 問題 使用類似Linux的顯示方式時無將資料備份至NTFS磁碟區

使用Acronis開機光碟進行有HDD壞軌進行備份,選擇NTFS外接式隨身碟,結果出現以下錯誤訊息: 使用類似Linux的顯示方式時無將資料備份至NTFS磁碟區.... 原來是一開始上方有個設定要開啟使用Windows的瀏覽模式才可以正常備份成功。 另外有壞軌的HDD在備份過程中會出現需要使用者互動的狀況,只要點選一率忽略即可,因為不忽略也不能往下運作了。

2015年4月1日 星期三

秒數轉換成天數公式作法 範例 php

首先因為要計算session的live time所以需要將以下類似這樣的結果進行轉換 Starttime Stoptime Sessiontime 2014-11-09 15:48:26 2014-11-14 14:24:00 426934 公式如下: function calcTime($diff){ $sec = $diff % 60; $sec2 = $diff/60; $min = $sec2 % 60; $min2 = $sec2 / 60; $hr = $min2 % 24; $hr2 = $min2 / 24; $day = $hr2 % 24; $result = $day ." 天 " . $hr . " 小時 " . $min . " 分鐘 " . $sec . " 秒"; return $result; } 換算出來的結果就是: 4 天 22 小時 35 分鐘 34 秒

2015年3月29日 星期日

C# Process Standard Output 隨手筆記

原本有些API在應用的時候,原本的想法就是透過Telnet的方式來呼叫進行互動式的操作。
但為了簡化環境的因子,想說如果可以利用C#呼叫外部程式的方式,進行溝通鳩可以了。
雖然事與願違,但還是將測試的過程進行了以下的紀錄。

Process process = new Process();
process.StartInfo.FileName = "cliprogram.exe";
process.StartInfo.UseShellExecute = false; //如果輸出導向的話此處要設定
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
//line += process.StandardError.ReadLine();
// do something with line
Console.WriteLine(line);
}

但我發現有些程式如果還在運行中,Standardoutput不認為輸出完成所以不會回傳值。
但如果用ReadLine();則僅能讀取第一行。

後續還有突破再補上。

CentOS Python 3.7 安裝方式

有些開發的程式在python 3.8的檔案套件不相容,例如pymssql,等。 所以如果不建置虛擬環境的話才特意安裝3.7版本的python 安裝流程如下 # 先進行yum套件的update yum update -y # 安裝相依性套件 yum install gcc o...