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