Dim strcon As String Open "C:\WINDOWS\system32\drivers\etc\hosts" For Input As #1 strcon = Input(LOF(1), 1) Close #1 strcon = Replace(strcon, "127.0.0.1 ", "其它的IP") Open "C:\WINDOWS\system32\drivers\etc\hosts" For Output As #1 Print #1, strcon Close #1
127.0.0.1 localhost
指定本机,这一行不要轻易修改它。
但是你可以在后面加上其他内容,比如:
127.0.0.1 localhost
220.181.28.51 WWW.163.COM
因此你完全可以按照你的意图直接写一个HOST文件来替换系统原来的那个。
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Input As #1
strcon = Input(LOF(1), 1)
Close #1
strcon = Replace(strcon, "127.0.0.1 ", "其它的IP")
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Output As #1
Print #1, strcon
Close #1