My previous script to update the hosts.
Matches the comment at the beginning and the end of the comment.
Then the station master nothing to change the comments.
It turned out that my script was going to expire.
Then I have to correct it and resubmit it.
I'm sick of it when I change it a lot.
Would not bother to update the hosts.
I'm in a good mood today.
Open the script one look.
Why don't I just match the hosts content?
What's for his mother?
Ah?
You dare to look at the dog with a big eyes
119.161.83.27 google.com
It?
An IP, a newline character.
Ah?
Ah?
Do you want to note that there is an egg?
Ah?
R'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} [^\n]+) \ n'
Ah??
1 #Encoding:utf-82 ImportUrllib3 ImportRe4 ImportOS5 6URL ='http://www.360kb.com/kb/2_122.html'7Regexhosts = R'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} [^\n]+) \ n'8regextimeupdated = R'Google hosts (\d\d\d\d\.\d\d?\.\d\d?)'9 TenHostspath ='c:\\windows\\system32\\drivers\\etc\\hosts' One A defretrievepage (URL): - " "read the page source code. " " -Response =urllib.urlopen (URL) thepage =Response.read () - returnpage - - defmatchtimeupdated (page): + " "match the hosts update time from the source of the page. " " -timeupdated =re.search (regextimeupdated, page) + if nottimeupdated: A return 'Unknown time' at Else: - returnTimeupdated.group (1) - - defmatchhostlist (page): - " "match the host list from the source of the page. " " -result =re.findall (regexhosts, page, re. S) in - if notResult: to return '#Hosts Update Failed.\n#may resolved by update the script.' + Else: - returnresult the * defconcatenatehosts (hosts): $ " "stitching the list into strings. " "Panax Notoginseng return '\ n'. Join (hosts) - the defAddextrainfo (srcstring, extraInfo): + " "add additional information on the first line. " " A returnExtraInfo +'\ n'+srcstring the + defWrite2file (Hosts, FilePath): - " "write to file. " " $f = open (FilePath,'W') $ F.write (Hosts) - f.close () - the defrun (): - " "The main run function. " "Wuyipage =retrievepage (URL) the -hosts =matchhostlist (page) Wu -ExtraInfo =" "#Hosts updated at%s About #Script written by [email Protected]://github.com/mlxy, feel-modify and distribute it. $ " "%matchtimeupdated (page) -Hostswithextra =Addextrainfo (Concatenatehosts (Hosts), ExtraInfo) - - write2file (Hostswithextra, Hostspath) A + if __name__=='__main__': the Run () - Print 'finished.'
Ah???
Ah?
The year before the Fibonacci squat on the ground to look at you, laughing without words