自动拨号及断线重拨
using System;
using 发送与接收IP;
using Microsoft.VisualBasic;
namespace AutoDial
{
public class Connect
{
int int_拨号进程ID;
static string string_拨号程序及参数="C:\\winnt\\system32\\rasphone.exe -d \"adsl\"";
static string string_挂断连接="C:\\winnt\\system32\\rasphone.exe -h \"adsl\"";
static string string_拨号进程名="rasphone";
static int int_重拨时间间隔=-1;
public Connect()
{
}
private bool 在线()
{
//有公网IP即为在线,没有公网IP为不在线
bool bool_在线;
string string_本机IP=发送与接收IP.class_发送IP.获取本机公网IP地址 ();
if (string_本机IP==null)
{
bool_在线=false;
}
else
{
bool_在线=true;
}
return bool_在线;
}
private bool 连接稳定()
{
try
{
System.Net .IPHostEntry IPHostEntry_天极网IP=System.Net .Dns .GetHostByName("www.yesky.com");
return true;
}
catch (System.Exception er)
{
return false;//连接不稳定
}
}
private void 启动拨号连接()
{
int_拨号进程ID = Microsoft.VisualBasic.Interaction.Shell(string_拨号程序及参数,AppWinStyle.MinimizedNoFocus ,true,int_重拨时间间隔);
}
private void 终止拨号进程()
{
System.Diagnostics .Process[] arrayProcess_计算机全部进程;
arrayProcess_计算机全部进程 =System.Diagnostics . Process.GetProcessesByName(string_拨号进程名);
foreach(System.Diagnostics .Process Process_单个进程 in arrayProcess_计算机全部进程)
{
Process_单个进程.Kill ();
}
}
private void 挂断连接()
{
int_拨号进程ID = Microsoft.VisualBasic.Interaction.Shell(string_挂断连接,AppWinStyle.MinimizedNoFocus ,true,int_重拨时间间隔);
}
public void 保持在线()
{
if (在线())
{
if (连接稳定())
{
return ;
}
else
{
挂断连接();
终止拨号进程();
启动拨号连接();
}
}
else
{
挂断连接();
终止拨号进程();
启动拨号连接();
}
}
}
}


浙公网安备 33010602011771号