0

I'd like to create short app that runs with windows start and execute flashdns for example every 1h. Maybe compile to into exe file.

I know that start of this will be:

import os
os.system('ipconfig/flushdns')

but i didn't find answer how this function will look like and how to compile it and run it with windows.

leszek
  • 3
  • 2

3 Answers3

0

This guide should get you covered, it shows how you can run and execute commands in cmd: https://datatofish.com/command-prompt-python/

Klatten
  • 307
  • 3
  • 16
0

To run your command on a schedule, you can use an infinite while loop and time.sleep, which takes a number of seconds to delay thread execution by:

import time
import os

while True:
    os.system("ipconfig /flushdns")
    time.sleep(3600)

If you are doing other things in this program, you may want to run this loop in a thread.

To "compile" your program into a Windows executable file, you can use py2exe or cx_Freeze (just some examples, there are certainly more tools available that have this functionality).

Tris
  • 296
  • 1
  • 4
0

Big Thanks to:

https://stackoverflow.com/users/9359583/kremklatt

I used links:

How to start a python file while Windows starts? https://datatofish.com/command-prompt-python/

And Final Script:

import os
import threading

def flushdns():
    threading.Timer(60.0, flushdns).start()  # repeat every 60 seconds
    os.system('cmd /k "ipconfig/flushdns"')

flushdns()

This Community is Epic xD

https://github.com/perdubaro/DnsFlusher

any feedback welcome :)

leszek
  • 3
  • 2