Python脚本会定期更改Mac地址

In this tutorial we will look a simple but useful code that changes windows operating system Mac address. Mac address is the unique address that specifies the network interface. A general thought that mac addresses can be changed. But is it not true. Mac addressee is provided by the network card to the operations system network stack. But can be changed by operating system with sufficient privileges.

在本教程中,我们将看到一个简单但有用的代码,该代码可以更改Windows操作系统的Mac地址。 Mac地址是指定网络接口的唯一地址。 人们普遍认为可以更改mac地址。 但这不是真的。 Mac地址由网卡提供给操作系统网络堆栈。 但是可以通过具有足够特权的操作系统进行更改。

从Github下载Periodic-Mac-Changer (Download Periodic-Mac-Changer From Github)

The code can be downloaded with the following git command.

可以使用以下git命令下载代码。

> git clone https://github.com/ibaydan/periodic-mac-changer.git

OR we can download from following link as compressed archive.

或者,我们可以从以下链接下载压缩存档。

https://github.com/ibaydan/periodic-mac-changer/archive/master.zip

https://github.com/ibaydan/periodic-mac-changer/archive/master.zip

Macshift.exe (Macshift.exe)

In order to do low level mac change operations we will use macshift.exe .macshift.exe as its name suggest changes the mac address of given interface. It is provided by git repository so we do not need to download explicitly.

为了进行低级的mac更改操作,我们将使用macshift.exemacshift.exe的名称建议更改给定接口的mac地址。 它由git仓库提供,因此我们不需要显式下载。

计时器 (Timer.py)

The periodic operations are managed by Timer.py python file. Here the simply code provided by Timer.py

定期操作由Timer.py python文件管理。 这是Timer.py提供的简单代码

import time 
import os 
 
while True: 
        time.sleep(5) 
        os.system('macshift.exe -i "Local Area Connection 3"')
  • We import time and os libraries in order to use related functions and API’s

    我们导入timeos库以使用相关功能和API

  • We create a while loop which is infinite python while loop in order to never end the process except CTR+C

    我们创建一个while循环,它是无限的python while循环,以便永远不会结束除CTR+C之外的进程

  • time.sleep(5) function is used  to sleep current loop for 5 seconds in every step.

    time.sleep(5)函数用于在每个步骤中将电流循环睡眠5秒钟。

  • os.system('macshift.exe -i "Local Connection 3"') is used provide macshift command to the operationg system whit related interface information which is Local Connection 3 in this example.

    os.system('macshift.exe -i "Local Connection 3"')用于向macshift相关接口信息提供macshift命令,在本示例中为Local Connection 3

LEARN MORE  Python Standard Library
了解更多Python标准库

翻译自: https://www.poftut.com/python-script-change-mac-address-periodically/

### 回答1: 你可以使用crontab来实现定时启动Mac上的程序。 你可以在终端中输入 crontab -e 命令,然后在文本编辑器中输入以下内容: * * * * * /path/to/program这将在每分钟都运行/path/to/program。你也可以根据自己的需要更改运行时间,例如每小时运行一次,每天运行一次等等。 ### 回答2: 要编写一个Python脚本,用于定时启动Mac上的程序,可以使用Python的内置模块`os`和`time`来实现。下面是一个简单的示例代码: ```python import os import time def start_program(program_path, delay): # 等待指定的延迟时间 time.sleep(delay) # 使用os模块执行命令,启动指定路径下的程序 os.system(f"open {program_path}") if __name__ == "__main__": # 设置程序路径和延迟时间 program_path = "/Applications/TextEdit.app" # 修改为要启动的程序的实际路径 delay = 10 # 延迟时间,单位为秒 # 调用函数启动程序 start_program(program_path, delay) ``` 在上面的示例代码中,`start_program`函数接受两个参数:`program_path`指定要启动的程序路径,`delay`表示延迟时间,即脚本运行后等待一段时间再启动程序。这里使用`time.sleep`函数来实现延迟。 在`start_program`函数中,使用`os.system`函数执行命令`open`来启动指定路径下的程序。这个示例中使用的是TextEdit.app作为示例,你可以根据需要修改`program_path`为你想要启动的程序的实际路径。 最后,在`if __name__ == "__main__":`语句中,设置了程序路径和延迟时间,并调用`start_program`函数来启动程序。 你可以将以上代码保存为一个Python脚本文件,比如`start_program.py`,然后在终端中运行该脚本(例如`python start_program.py`),程序将在延迟时间后启动。 ### 回答3: 要编写一个 Python 脚本以定时启动 Mac 上的程序,可以使用 `os` 模块来执行系统命令。以下是一个实例: ```python import os import time def start_program(): program_path = "/Applications/Calculator.app" # 替换为要启动的程序的路径或命令 os.system(f"open {program_path}") def main(): interval = 3600 # 以秒为单位设置时间间隔,这里设置为一小时 while True: start_program() time.sleep(interval) if __name__ == "__main__": main() ``` 在上面的例子中,`start_program` 函数用来启动指定的程序。你需要将 `program_path` 变量替换为实际程序的路径或命令。例如,这里我用的是计算器应用程序。 `main` 函数在一个死循环中定时调用 `start_program` 函数。时间间隔可以通过 `interval` 变量来调整,这里设置为一个小时(3600秒)。 这个脚本不断地启动程序,然后等待指定的时间间隔后再次启动。可以使用 `Ctrl + C` 组合键来中断脚本的运行。 请注意,为了能够在 Mac 上执行该脚本,你需要安装 Python,然后通过终端运行该脚本
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值