用C#实现宽带重新拨号
2012-09-23 15:47
519 查看
我们做一些软件的时候常常要用到换IP的操作,其实简单的换IP的方法就是重新拨号啊,下面就是我实践成功的重新拨号的代码,很简单的,是一个单独的类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;//诊断,调用进程
namespace QQ号批量注册
{
class ADSLHelper
{
public void Connect(string connectionName, string user, string pass)
{
string arg = string.Format("rasdial \"{0}\" {1} {2}", connectionName, user, pass);
InvokeCmd(arg);
}
public void Disconnect(string connectionName)
{
string arg = string.Format("rasdial \"{0}\" /disconnect", connectionName);
InvokeCmd(arg);
}
public static string InvokeCmd(string cmdArgs)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdArgs);
p.StandardInput.WriteLine("exit");
return p.StandardOutput.ReadToEnd();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;//诊断,调用进程
namespace QQ号批量注册
{
class ADSLHelper
{
public void Connect(string connectionName, string user, string pass)
{
string arg = string.Format("rasdial \"{0}\" {1} {2}", connectionName, user, pass);
InvokeCmd(arg);
}
public void Disconnect(string connectionName)
{
string arg = string.Format("rasdial \"{0}\" /disconnect", connectionName);
InvokeCmd(arg);
}
public static string InvokeCmd(string cmdArgs)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdArgs);
p.StandardInput.WriteLine("exit");
return p.StandardOutput.ReadToEnd();
}
}
}
相关文章推荐
- 用C#实现宽带重新拨号
- 用C#实现宽带重新拨号
- 用C#实现宽带重新拨号
- C# 网络营销 - c#可以实现连接和断开宽带的拨号程序吗?
- c#可以实现连接和断开宽带的拨号程序吗?
- 黑马程序员之C#编程基础学习笔记:用while break实现要求用户输入用户名和密码,只要不是admin,888888就一直提示要求重新输入。
- C# ADSL重新连接、拨号
- 用树莓派实现宽带多次拨号,带宽叠加
- C#接口深度剖析(子类重新实现)
- 使用C#实现ADSL自动拨号
- 在Vista中轻松实现宽带自动拨号
- vs2015 C#实现usb虚拟串口自动识别和重新连接
- 《模式——工程化实现及扩展》(设计模式C# 版)《重新研读C#语言》——“自我检验" 参考答案:配置访问部分
- 重新研读C#语言——《设计模式—基于C#的工程化实现及扩展》
- 【转】使用C#实现ADSL自动拨号
- C# 实现ADSL自动断网和拨号(适用于拨号用户)
- 使用C#实现ADSL自动拨号
- 巧用批处理文件实现宽带自动拨号
- Qt实现Rasdial宽带拨号
- C#中重新定义Console实现自动保存输出到文件