0

I have the following code:

import re
import os
import fileinput


textToSearch = ('127.16.129.')

print ("Your IP Address:")
textToReplace = input('127.16.129.' + "> " )

fileToSearch = "C:/Windows/system32/drivers/etc/hosts"

tempFile = open( fileToSearch, 'r+' )

for line in fileinput.input(fileToSearch, inplace=True):
    print(line.replace(textToSearch, textToReplace))

tempFile.write( line.replace( textToSearch, textToReplace ) )
tempFile.close()


input( '\n\n Press Enter to exit...' )

I'm trying to change the IP address in my hosts file to use on my VMWare machine, this has to be done due to roaming profiles and changing computers quite a bit so this script will make it easier to change the IP address in the hosts file.

When I run this script I get the error "IOError: [Errno 13] Permission denied". I have administrator rights I just need to be able to run the script as admin. I am also running on a Windows environment.

poldy
  • 204
  • 3
  • 12

0 Answers0