2006年10月18日 星期三 08:57
Çë½Ì¸öÎÊÌâ ÈçÌâ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/2d0d0e69/attachment.htm
2006年10月18日 星期三 09:14
在06-10-18,Guofeng Yuan <loocoo at gmail.com> 写道: > > 请教个问题 如题 > 重启网络是什么意思?你是怎么重启的?在windows下要设置ip我想可以调用netsh,具体的可以看下windows下netsh的帮助 -- I like Python & Linux. Blog: http://recordus.cublog.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/99a02a5d/attachment.html
2006年10月18日 星期三 09:18
这个 比较麻烦吧, 以前看过一篇 文章 重设 IP 的, C 实现的。 用了一个 未公开的 API 代码 如下: BOOL RegSetIP(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, LPCTSTR pNetMask, LPCTSTR pNetGate) { HKEY hKey; CString strKeyName = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; strKeyName += lpszAdapterName; if(RegOpenKeyEx (HKEY_LOCAL_MACHINE,strKeyName.GetString(), 0, KEY_WRITE, &hKey;) != ERROR_SUCCESS) { return FALSE; } char mszIPAddress[100]; char mszNetMask[100]; char mszNetGate[100]; strncpy(mszIPAddress, pIPAddress, 98); strncpy(mszNetMask, pNetMask, 98); strncpy(mszNetGate, pNetGate, 98); int nIP, nMask, nGate; nIP = (int)strlen(mszIPAddress); nMask = (int)strlen(mszNetMask); nGate = (int)strlen(mszNetGate); *(mszIPAddress + nIP + 1) = 0x00; nIP += 2; *(mszNetMask + nMask + 1) = 0x00; nMask += 2; *(mszNetGate + nGate + 1) = 0x00; nGate += 2; RegSetValueEx(hKey, "IPAddress", 0, REG_MULTI_SZ, (unsigned char*)mszIPAddress, nIP); RegSetValueEx(hKey, "SubnetMask", 0, REG_MULTI_SZ, (unsigned char*)mszNetMask, nMask); RegSetValueEx(hKey, "DefaultGateway", 0, REG_MULTI_SZ, (unsigned char*)mszNetGate, nGate); RegCloseKey(hKey); return TRUE; } BOOL NotifyIPChange(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, LPCTSTR pNetMask) { BOOL bResult = FALSE; HINSTANCE hDhcpDll; DHCPNOTIFYPROC pDhcpNotifyProc; WCHAR wcAdapterName[256]; MultiByteToWideChar(CP_ACP, 0, lpszAdapterName, -1, wcAdapterName,256); if((hDhcpDll = LoadLibrary("dhcpcsvc")) == NULL) { return FALSE; } if((pDhcpNotifyProc = (DHCPNOTIFYPROC)GetProcAddress(hDhcpDll, "DhcpNotifyConfigChange")) != NULL) { if((pDhcpNotifyProc)(NULL, wcAdapterName, TRUE, nIndex, inet_addr(pIPAddress), inet_addr(pNetMask), 0) == ERROR_SUCCESS) { bResult = TRUE; } } FreeLibrary(hDhcpDll); return bResult; } BOOL SetIP(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, LPCTSTR pNetMask, LPCTSTR pNetGate) { if(!RegSetIP(lpszAdapterName, nIndex, pIPAddress, pNetMask, pNetGate)) { return FALSE; } if(!NotifyIPChange(lpszAdapterName, nIndex, pIPAddress, pNetMask)) { return FALSE; } return TRUE; }
2006年10月18日 星期三 09:34
ÖØÆôÍøÂç¾ÍÊÇÏÈ°ÑÍø¿¨½ûÓã¬ÔÙÆôÓà ÖØÉèipÊÇÓе㷳£¬²»¹ý¿ÉÒÔÓÃdhcpµÄ·½Ê½¼ò»¯ Ò²¾Í±ä³ÉÁËÖ´ÐÐipconfig releaseÃüÁîÁË£¬ СÉùµÄÎÊһϠpythonÕ¦Ö´ÐÐϵͳÃüÁ On 10/18/06, lu <lubiao.py在gmail.com> wrote: > > Õâ¸ö ±È½ÏÂé·³°É£¬ ÒÔÇ°¿´¹ýһƪ ÎÄÕ ÖØÉè IP µÄ£¬ > C ʵÏֵġ£ > > ÓÃÁËÒ»¸ö δ¹«¿ªµÄ API > ´úÂë ÈçÏ£º > BOOL RegSetIP(LPCTSTR lpszAdapterName, > > int nIndex, > > LPCTSTR pIPAddress, > > LPCTSTR pNetMask, > > LPCTSTR pNetGate) > > { > > HKEY hKey; > > CString strKeyName = > > > "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; > > strKeyName += lpszAdapterName; > > if(RegOpenKeyEx > > (HKEY_LOCAL_MACHINE,strKeyName.GetString(), 0, KEY_WRITE, > &hKey;) != > ERROR_SUCCESS) > > { > > return FALSE; > > } > > char mszIPAddress[100]; > > char mszNetMask[100]; > > char mszNetGate[100]; > > > > strncpy(mszIPAddress, pIPAddress, 98); > > strncpy(mszNetMask, pNetMask, 98); > > strncpy(mszNetGate, pNetGate, 98); > > > > int nIP, nMask, nGate; > > > > nIP = (int)strlen(mszIPAddress); > > nMask = (int)strlen(mszNetMask); > > nGate = (int)strlen(mszNetGate); > > > > *(mszIPAddress + nIP + 1) = 0x00; > > nIP += 2; > > > > *(mszNetMask + nMask + 1) = 0x00; > > nMask += 2; > > > > *(mszNetGate + nGate + 1) = 0x00; > > nGate += 2; > > > > RegSetValueEx(hKey, "IPAddress", 0, REG_MULTI_SZ, (unsigned > char*)mszIPAddress, nIP); > > RegSetValueEx(hKey, "SubnetMask", 0, REG_MULTI_SZ, (unsigned > char*)mszNetMask, nMask); > > RegSetValueEx(hKey, "DefaultGateway", 0, REG_MULTI_SZ, (unsigned > char*)mszNetGate, nGate); > > > > RegCloseKey(hKey); > > > > return TRUE; > > } > > > > > > > > BOOL NotifyIPChange(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR > pIPAddress, LPCTSTR pNetMask) > > { > > BOOL bResult = FALSE; > > HINSTANCE hDhcpDll; > > DHCPNOTIFYPROC pDhcpNotifyProc; > > WCHAR wcAdapterName[256]; > > > > MultiByteToWideChar(CP_ACP, 0, lpszAdapterName, -1, > wcAdapterName,256); > > > > if((hDhcpDll = LoadLibrary("dhcpcsvc")) == NULL) > > { > > return FALSE; > > } > > > > if((pDhcpNotifyProc = (DHCPNOTIFYPROC)GetProcAddress(hDhcpDll, > "DhcpNotifyConfigChange")) != NULL) > > { > > if((pDhcpNotifyProc)(NULL, wcAdapterName, TRUE, nIndex, > inet_addr(pIPAddress), inet_addr(pNetMask), 0) == ERROR_SUCCESS) > > { > > bResult = TRUE; > > } > > } > > > > FreeLibrary(hDhcpDll); > > return bResult; > > } > > BOOL SetIP(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, > LPCTSTR pNetMask, LPCTSTR pNetGate) > > { > > if(!RegSetIP(lpszAdapterName, nIndex, pIPAddress, pNetMask, > pNetGate)) > > { > > return FALSE; > > } > > > > if(!NotifyIPChange(lpszAdapterName, nIndex, pIPAddress, pNetMask)) > > { > > return FALSE; > > } > > > > return TRUE; > > } > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/e5ac271a/attachment.htm
2006年10月18日 星期三 09:41
os.system() Ò»»áÊÔÊÔ On 10/18/06, Guofeng Yuan <loocoo在gmail.com> wrote: > > ÖØÆôÍøÂç¾ÍÊÇÏÈ°ÑÍø¿¨½ûÓã¬ÔÙÆôÓà > > ÖØÉèipÊÇÓе㷳£¬²»¹ý¿ÉÒÔÓÃdhcpµÄ·½Ê½¼ò»¯ Ò²¾Í±ä³ÉÁËÖ´ÐÐipconfig releaseÃüÁîÁË£¬ > > СÉùµÄÎÊһϠpythonÕ¦Ö´ÐÐϵͳÃüÁ > > On 10/18/06, lu < lubiao.py在gmail.com> wrote: > > > > Õâ¸ö ±È½ÏÂé·³°É£¬ ÒÔÇ°¿´¹ýһƪ ÎÄÕ ÖØÉè IP µÄ£¬ > > C ʵÏֵġ£ > > > > ÓÃÁËÒ»¸ö δ¹«¿ªµÄ API > > ´úÂë ÈçÏ£º > > BOOL RegSetIP(LPCTSTR lpszAdapterName, > > > > int nIndex, > > > > LPCTSTR pIPAddress, > > > > LPCTSTR pNetMask, > > > > LPCTSTR pNetGate) > > > > { > > > > HKEY hKey; > > > > CString strKeyName = > > > > > > "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; > > > > strKeyName += lpszAdapterName; > > > > if(RegOpenKeyEx > > > > (HKEY_LOCAL_MACHINE,strKeyName.GetString(), 0, > > KEY_WRITE, &hKey;) != > > ERROR_SUCCESS) > > > > { > > > > return FALSE; > > > > } > > > > char mszIPAddress[100]; > > > > char mszNetMask[100]; > > > > char mszNetGate[100]; > > > > > > > > strncpy(mszIPAddress, pIPAddress, 98); > > > > strncpy(mszNetMask, pNetMask, 98); > > > > strncpy(mszNetGate, pNetGate, 98); > > > > > > > > int nIP, nMask, nGate; > > > > > > > > nIP = (int)strlen(mszIPAddress); > > > > nMask = (int)strlen(mszNetMask); > > > > nGate = (int)strlen(mszNetGate); > > > > > > > > *(mszIPAddress + nIP + 1) = 0x00; > > > > nIP += 2; > > > > > > > > *(mszNetMask + nMask + 1) = 0x00; > > > > nMask += 2; > > > > > > > > *(mszNetGate + nGate + 1) = 0x00; > > > > nGate += 2; > > > > > > > > RegSetValueEx(hKey, "IPAddress", 0, REG_MULTI_SZ, (unsigned > > char*)mszIPAddress, nIP); > > > > RegSetValueEx(hKey, "SubnetMask", 0, REG_MULTI_SZ, (unsigned > > char*)mszNetMask, nMask); > > > > RegSetValueEx(hKey, "DefaultGateway", 0, REG_MULTI_SZ, (unsigned > > > > char*)mszNetGate, nGate); > > > > > > > > RegCloseKey(hKey); > > > > > > > > return TRUE; > > > > } > > > > > > > > > > > > > > > > BOOL NotifyIPChange(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR > > pIPAddress, LPCTSTR pNetMask) > > > > { > > > > BOOL bResult = FALSE; > > > > HINSTANCE hDhcpDll; > > > > DHCPNOTIFYPROC pDhcpNotifyProc; > > > > WCHAR wcAdapterName[256]; > > > > > > > > MultiByteToWideChar(CP_ACP, 0, lpszAdapterName, -1, > > wcAdapterName,256); > > > > > > > > if((hDhcpDll = LoadLibrary("dhcpcsvc")) == NULL) > > > > { > > > > return FALSE; > > > > } > > > > > > > > if((pDhcpNotifyProc = (DHCPNOTIFYPROC)GetProcAddress(hDhcpDll, > > "DhcpNotifyConfigChange")) != NULL) > > > > { > > > > if((pDhcpNotifyProc)(NULL, wcAdapterName, TRUE, nIndex, > > inet_addr(pIPAddress), inet_addr(pNetMask), 0) == ERROR_SUCCESS) > > > > { > > > > bResult = TRUE; > > > > } > > > > } > > > > > > > > FreeLibrary(hDhcpDll); > > > > return bResult; > > > > } > > > > BOOL SetIP(LPCTSTR lpszAdapterName, int nIndex, LPCTSTR pIPAddress, > > LPCTSTR pNetMask, LPCTSTR pNetGate) > > > > { > > > > if(!RegSetIP(lpszAdapterName, nIndex, pIPAddress, pNetMask, > > pNetGate)) > > > > { > > > > return FALSE; > > > > } > > > > > > > > if(!NotifyIPChange(lpszAdapterName, nIndex, pIPAddress, > > pNetMask)) > > > > { > > > > return FALSE; > > > > } > > > > > > > > return TRUE; > > > > } > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/2d66c141/attachment.html
2006年10月18日 星期三 09:59
On 2006年10月18日 09:34, Guofeng Yuan write: > 重启网络就是先把网卡禁用,再启用 > > 重设ip是有点烦,不过可以用dhcp的方式简化 也就变成了执行ipconfig > release命令了, > > 小声的问一下 python咋执行系统命令? 为什么非要用Python?如果是控制windows 2k以上版本的系统的网络设置,用官方 提供的netsh就好了,编写脚本一样很方便。
2006年10月18日 星期三 12:26
-------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/41adda69/attachment.html
2006年10月18日 星期三 21:45
woooo. netsh 好酷啊,好像路由器/交换机的配置界面。。。偶是土人,感叹一下
2006年10月18日 星期三 22:05
不错,以前也没有用过netsh 2006/10/18, Yingbo Qiu <qiuyingbo at gmail.com>: > > woooo. netsh 好酷啊,好像路由器/交换机的配置界面。。。偶是土人,感叹一下 > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/eda35ccc/attachment.htm
2006年10月18日 星期三 22:06
-------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/71858e93/attachment.html
2006年10月18日 星期三 22:27
其实从Win2K开始,MS就已经开始提供了很多命令行和WSH脚本语言给管理员使用了。虽说比起类UNIX系统的命令行及脚本还有些距离,但基本上也能通过命令行实现window几乎所有的管理工作了。MS还是很厉害的! On 10/18/06, soulhacker511 at 163.com <soulhacker511 at 163.com> wrote: > > python-chinese,你好 > > 算bill有良心,给我们的工具里面这个很有用。其他很多是鸡肋 > Guradian,soulhacker511 at 163.com > 2006-10-18 > > ----- Original Message ----- > *From: * Yingbo Qiu <qiuyingbo at gmail.com> > *To: * python-chinese <python-chinese at lists.python.cn> > *Sent: * 2006-10-18, 21:45:24 > *Subject: * Re: [python-chinese]python在windows下 如何重启网络 重新设置ip呀? > > woooo. netsh 好酷啊,好像路由器/交换机的配置界面。。。偶是土人,感叹一下 > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn<+python-chinese at lists.python.cn> > Subscribe: send subscribe to python-chinese-request at lists.python.cn<+python-chinese-request at lists.python.cn> > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn<+python-chinese-request at lists.python.cn> > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Just do it! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061018/7ce78232/attachment.htm
2006年10月19日 星期四 10:14
Õâ¸önetshÕæºÃ£¬ÄÇÓÐûÓÐÃüÁî½ûÓà ÆôÓÃÍø¿¨ÄØ£¿ On 10/18/06, Jun Liu <liujun.gz在gmail.com> wrote: > > > Æäʵ´ÓWin2K¿ªÊ¼£¬MS¾ÍÒѾ¿ªÊ¼ÌṩÁ˺ܶàÃüÁîÐкÍWSH½Å±¾ÓïÑÔ¸ø¹ÜÀíԱʹÓÃÁË¡£Ëä˵±ÈÆðÀàUNIXϵͳµÄÃüÁîÐм°½Å±¾»¹ÓÐЩ¾àÀ룬µ«»ù±¾ÉÏÒ²ÄÜͨ¹ýÃüÁîÐÐʵÏÖwindow¼¸ºõËùÓеĹÜÀí¹¤×÷ÁË¡£MS»¹ÊǺÜÀ÷º¦µÄ£¡ > > On 10/18/06, soulhacker511在163.com <soulhacker511在163.com> wrote: > > > > python-chinese£¬ÄãºÃ > > > > ËãbillÓÐÁ¼ÐÄ£¬¸øÎÒÃǵŤ¾ßÀïÃæÕâ¸öºÜÓÐÓá£ÆäËûºÜ¶àÊǼ¦Àß > > Guradian£¬ soulhacker511在163.com > > 2006-10-18 > > > > ----- Original Message ----- > > *From: * Yingbo Qiu <qiuyingbo在gmail.com> > > *To: * python-chinese <python-chinese在lists.python.cn> > > *Sent: * 2006-10-18, 21:45:24 > > *Subject: * Re: [python-chinese]pythonÔÚwindowsÏ ÈçºÎÖØÆôÍøÂç ÖØÐÂÉèÖÃipѽ£¿ > > > > woooo. netsh ºÃ¿á°¡£¬ºÃÏñ·ÓÉÆ÷/½»»»»úµÄÅäÖýçÃæ¡£¡£¡£Å¼ÊÇÍÁÈË£¬¸Ð̾һÏ > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn<+python-chinese在lists.python.cn> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn<+python-chinese-request在lists.python.cn> > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn<+python-chinese-request在lists.python.cn> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > -- > Just do it! > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061019/3151c46a/attachment-0001.htm
2006年10月19日 星期四 12:10
-------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061019/6150cdce/attachment.html
Zeuux © 2025
京ICP备05028076号