Last-modified: 2006-02-28 (火) 15:40:43 (6624d)

 環境によって、Webブラウザのプロキシ設定を変更したいときに使うJavaScriptのサンプルです。利用者、利用環境によって、適宜、内容の変更が必要でしょうね。

function FindProxyForURL(url, host) {
    // my computer is in network:A...
    if (myIpAddress().substring(0, 11) == "192.168.130"
     || myIpAddress().substring(0, 11) == "192.168.140"
     || myIpAddress().substring(0, 10) == "192.168.80") {

        // destination host is in LAN...
        if (isPlainHostName(host)
         || isInNet(host, "10.0.0.0", "255.0.0.0")
         || isInNet(host, "127.0.0.0", "255.0.0.0")
         || isInNet(host, "192.168.0.0", "255.255.0.0")) {
            return "DIRECT";
        } else {
            return "PROXY 192.168.0.1:80";
        }

    // my computer is in network:B...
    } else if (myIpAddress().substring(0, 3) == "10.") {

        // destination host is in LAN...
        if (isPlainHostName(host)
         || isInNet(host, "10.0.0.0", "255.0.0.0")
         || isInNet(host, "127.0.0.0", "255.0.0.0")
         || isInNet(host, "192.168.0.0", "255.255.0.0")
         || shExpMatch(host, "*.hosts-in-lan.jp")) {
            return "DIRECT";
        } else {
            return "PROXY proxy.hosts-in-lan.jp:8080";
        }

    // my computer directly connects to internet...
    } else {
        return "DIRECT";
    }
}

 IEの「インターネット オプション」「ローカルエリア ネットワーク(LAN)の設定」「自動構成スクリプトを使用する」をチェックし、このファイルを指定します。ちなみに、IE6.0だと、fileプロトコルは受け付けないみたいですね。

setting_ie.png

 ネットワーク設定の切り替えソフトウェアとしては、Sony Smart NetworkやThinkPadに付属のツールが高機能ですけど、対応しているのはIE用の設定だけで、FirefoxやNetscapeの設定を変えてはくれないです。そういう場合、このScriptが役に立ちますね。

setting_firefox.png

添付ファイル: fileproxy.pac 3698件 [詳細] filesetting_firefox.png 1845件 [詳細] filesetting_ie.png 1876件 [詳細]

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS