我的第一篇博客分享,写这个代码的用途是在公司Ghost完系统之后去修改本地计算机名称及IP 地址,用Powershell实现. 1. 代码第一部分,检查Powershell是否已管理员权限执行,如果不是的话,强制以管理员权限开启一个powershell窗口. #region Key code: force to run with administrator rights $currentWi = [Security.Principal.WindowsIdentity]::GetCurrent()
类的代码如下: using System; using System.Net; using System.Text.RegularExpressions; namespace Keleyi.Com { public class GetInternetIP { public static string GetIP() { using (var webClient = new WebClient()) { try { var temp = webClient.DownloadString("http
5行代码获取到本机的公网IP from urllib.request import urlopen import re text = str(urlopen("http://txt.go.sohu.com/ip/soip").read()) ip = re.findall(r'\d+.\d+.\d+.\d+',text) print(ip[0])