Archive

Posts Tagged ‘Windows’

Sleeping in a .BAT script

December 14th, 2009 BianJiang No comments

这里有列了两个方法:

1. Ping 实现

@ECHO OFF

rem –#——————————————————————

rem –# Script : sleep.BAT

rem –# Tested : Microsoft Windos XP [Version 5.1.2600]

rem –# Purpose : Sleep for number of seconds

rem –# Every 2 pings to localhost takes about 1 second

rem –#

rem –# Usage : sleep.BAT {# of seconds to sleep}

rem –#——————————————————————

ECHO %TIME%

FOR /l %%a IN (%1,-1,1) do (ECHO 1 >NULL %%as&ping -n 2 -w 1 127.0.0.1>NUL)

ECHO %TIME%

2. VBScript 实现

@echo off

echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs

cscript //b //nologo %tmp%\delay.vbs 5000

del %tmp%\delay.vbs > nul

当然你也可以用C自己写个。

参考: http://it.toolbox.com/blogs/database-solutions/sleeping-in-a-bat-script-22111

Categories: Tech.Notes Tags: , , ,

Google发布免费DNS解析服务

December 4th, 2009 BianJiang No comments

本文来自: Solidot.
Google宣布 推出免费的DNS解析服务Google Public DNS

DNS协议是Web的重要组成部分,它就如同是互联网的“电话簿”。每次访问一个网站,计算机都须执行一次DNS查询。复杂的网页在载入之前需执行多次DNS查询,其结果是普通网民每天必须执行数百次DNS查询,这会降低用户的浏览体验。Google推出Public DNS便是试图改进浏览体验,让互联网变得更快(在TTL记录过期之前执行prefetching,更新缓存),更安全(支持新的DNS安全扩展DNSSEC)。Google Public DNS托管在Google分布在全世界的数据中心,它使用选播路由算法(Anycast Routing)把用户的DNS解析请求发送到地理位置最近的数据中心。Google Public DNS遵循DNS标准,向用户的计算机提供正确的响应,不会有任何屏蔽、过滤,或重新定向等妨碍用户浏览体验的行为。Google Public DNS的IP地址为:8.8.8.8以及8.8.4.4。

修改TCP/IP的DNS服务器地址:

Microsoft Windows

DNS settings are specified in the TCP/IP Properties window for the selected network connection.

Example: Changing DNS server settings on Microsoft Windows Vista

  1. Go the Control Panel.
  2. Click Network and Internet, then Network and Sharing Center, then Manage network connections.
  3. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, right-click Local Area Connection, and click Properties.
    • To change the settings for a wireless connection, right-click Wireless Network Connection, and click Properties.

    If you are prompted for an administrator password or confirmation, type the password or provide confirmation.

  4. Select the Networking tab. Under This connection uses the following items, clickInternet Protocol Version 4 (TCP/IPv4), and then click Properties.
  5. Click Advanced and select the DNS tab. If there are any DNS server IP addresses listed there, write them down for future reference, and remove them from this window.
  6. Click OK.
  7. Select Use the following DNS server addresses. If there are any IP addresses listed in the Preferred DNS server or Alternate DNS server, write them down for future reference.
  8. Replace those addresses with the IP addresses of the Google DNS servers: 8.8.8.8 and 8.8.4.4.
  9. Restart the connection you selected in step 3.
  10. Test that your setup is working correctly; see Testing your new settings below.
  11. Repeat the procedure for additional network connections you want to change.

Mac OS X

DNS settings are specified in the Network window.

Example: Changing DNS server settings on Mac OS 10.5

  1. From the Apple menu, click System Preferences, then click Network. If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
  2. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced.
    • To change the settings for a wireless connection, select Airport, and clickAdvanced.
  3. Select the DNS tab.
  4. Click + to replace any listed addresses with, or add, the Google IP addresses at the top of the list: 8.8.8.8 and 8.8.4.4.
  5. Click Apply and OK.
  6. Test that your setup is working correctly; see Testing your new settings below.
  7. Repeat the procedure for additional network connections you want to change.

Linux

DNS settings are specified in /etc/resolv.conf in most distributions.

Example: Changing DNS server settings on Ubuntu

  1. Edit /etc/resolv.conf:
    sudo vi /etc/resolv.conf
  2. If any nameserver lines appear, write down the IP addresses for future reference.
  3. Replace the nameserver lines with, or add, the following lines:
    nameserver 8.8.8.8
    nameserver 8.8.4.4
  4. Save and exit.
  5. Restart any Internet clients you are using.
  6. Test that your setup is working correctly; see Testing your new settings below.


Bian Jiang
Blog: http://www.wifihack.net/

Categories: Others Tags: , , , ,

利用SSH实现加密代理

April 20th, 2009 BianJiang No comments

1. linux/unix
OpenSSH 支持SOCKS4和SOCKS5, 我们可以通过参数 -D 在本地创建一个代理端口. 例如:

ssh -D  12345 myuser@remote_ssh_server

我们已经在本地创建的一个SOCKS的端口12345, 现在你可以通过修改你的IE, Firefox 中的连接方式来用代理上网。比如:

IP 改为 127.0.0.1
端口: 12345
方式改为: SOCKS5

这样我们就可以继续访问 youtube 了。
2. 如果是windows 可以使用 putty的后台命令行程序plink(http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

plink -N username@remote.ssh.server -D 127.0.0.1:7070

其中 -N 表示不需要shell
username@remote.ssh.server 换成你ssh帐户名和主机域名或者地址
或者替换成 -load sessionname 也可以,用dreamhost上的帐号试了一下,真的很快
如果你用的是 Firefox 可以用SwitchProxy(https://addons.mozilla.org/en-US/firefox/addon/125), 非常方便的切换。
ssh -D 参数的描述:

-D [bind_address:]port
Specifies a local “dynamic” application-level port forwarding.  This works by allocating a
socket to listen to port on the local side, optionally bound to the specified bind_address.
Whenever a connection is made to this port, the connection is forwarded over the secure chan-
nel, and the application protocol is then used to determine where to connect to from the
remote machine.  Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as
a SOCKS server.  Only root can forward privileged ports.  Dynamic port forwardings can also
be specified in the configuration file.

IPv6 addresses can be specified with an alternative syntax: [bind_address/]port or by enclos-
ing the address in square brackets.  Only the superuser can forward privileged ports.  By
default, the local port is bound in accordance with the GatewayPorts setting.  However, an
explicit bind_address may be used to bind the connection to a specific address.  The
bind_address of “localhost” indicates that the listening port be bound for local use only,
while an empty address or ‘*’ indicates that the port should be available from all inter-
faces.

3.摘自chedong.com

ssh -qTfnN -D 7070 remotehost.

All the added options are for a ssh session that’s used for tunneling.

-q :- be very quite, we are acting only as a tunnel.
-T :- Do not allocate a pseudo tty, we are only acting a tunnel.
-f :- move the ssh process to background, as we don’t want to interact with this ssh session directly.
-N :- Do not execute remote command.
-n :- redirect standard input to /dev/null.

Links:
1. Use ssh create http proxy (http://www.linuxjournal.com/content/use-ssh-create-http-proxy)
2. http://www.chedong.com/blog/archives/001246.html
3. Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
Bian Jiang
http://www.wifihack.net

–EOF–

Categories: Tech.Notes Tags: , , , , ,

微软 Zune 30 又现千年虫Bug

January 1st, 2009 BianJiang No comments

在2008年的最后一天,无数的Zune 30 用户忽然发现自己的MP3无法正常播放,而专家给出的解决方法是:

“let the Zune run out of battery and the clock bug will essentially fix itself”

(让电池耗尽或这一天不要用Zune,到第二天就会自己好起来),但是这个Bug会四年后的今天再现。

在国外的一个论坛上看到一个帖子说Bug产生的原因, 当时闰年的时候天数是366天,下面的是Zune的 时钟驱动:

year = ORIGINYEAR; /* = 1980 */

while (days > 365)
{
    if (IsLeapYear(year))
    {
        if (days > 366)  // 当在闰年的时候,days = 366 是出现死循环
        {
            days -= 366;
            year += 1;
        }
    }
    else
    {
        days -= 365;
        year += 1;
    }
}

我们会发现当 days = 366 天的时候,while 就会进入死循环,直到24小时过后,才能正常工作。

当然还有一种修改驱动的方法:

year = ORIGINYEAR; /* = 1980 */

while (days > 365)
{
    if (IsLeapYear(year))
    {
        if (days > 366)
        {
            days -= 366;
            year += 1;
        }
        else  // 可以修复Bug
        {
            break;
        }
    }
    else
    {
        days -= 365;
        year += 1;
    }
}
参考:
1.Cause of Zune 30 leapyear problem ISOLATED!
http://www.zuneboards.com/forums/zune-news/38143-cause-zune-30-leapyear-problem-isolated.html
2.Zune 时钟驱动
http://pastie.org/349916
3.The Day the Zunes Stood Still: Update
http://www.crunchgear.com/2008/12/31/the-day-the-zunes-stood-still-update/

–EOF–

Categories: Geek Tags: ,