Advertisement
Guest User

Untitled

a guest
Jan 6th, 2012
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.25 KB | None | 0 0
  1. #RequireAdmin ; Just for manipulating hosts file
  2. main()
  3.  
  4. Func main()
  5.  
  6.     Local Const $Hostname = "www.autoitscript.com"
  7.     Local Const $URL = "http://" & $Hostname & "/"
  8.     Local Const $HostnameToLocalhost = "127.0.0.1 " & $Hostname ; redirect the hostname to localhost IP
  9.     Local Const $hosts = @WindowsDir & "\system32\drivers\etc\hosts"
  10.  
  11.     $BINSource = InetRead($URL, 1) ; get binary index.html forcing reload
  12.     $STRSource = BinaryToString($BINSource) ; transforms into a string
  13.  
  14.     MsgBox(0,"Before redirection",$STRSource) ; displays data before redirection
  15.  
  16.     ;backup hosts
  17.  
  18.     $hostsHandle = FileOpen($hosts)
  19.     $hostsBackup = FileRead($hostsHandle)
  20.     FileClose($hostsHandle)
  21.  
  22.     ;redirect hostname to localhost
  23.  
  24.     $hostsHandle = FileOpen($hosts, 1)
  25.     FileWrite($hostsHandle, @CRLF & $HostnameToLocalhost)
  26.     FileClose($hostsHandle)
  27.  
  28.     ;delay for redirection
  29.  
  30.     Sleep(5000)
  31.  
  32.     ;try to get source code again
  33.  
  34.     $BINSource = InetRead($URL, 1) ; get binary index.html forcing reload
  35.     $STRSource = BinaryToString($BINSource) ; transforms into a string
  36.  
  37.     MsgBox(0,"After redirection", $STRSource) ; displays data after redirection
  38.  
  39.     ;restore hosts
  40.  
  41.     $hostsHandle = FileOpen($hosts, 2)
  42.     FileWrite($hostsHandle, $hostsBackup)
  43.     FileClose($hostsHandle)
  44.  
  45. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement