static int RouteTableSearch(string type)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
string rootpath = path.Substring(0, path.LastIndexOf("bin"));
string batFile;
string key;
if (type == "add")
{
batFile = rootpath + @"Resources\route\vpnup.bat";
key = "route add";
}
else
{
batFile = rootpath + @"Resources\route\downup.bat";
key = "route delete";
}
if (File.Exists(batFile))
{
using (var sr = new StreamReader(batFile))
{
var content = sr.ReadToEnd();
Regex r = new Regex(key);
Match m = r.Match(content);
int matchCount = 0;
while (m.Success)
{
++matchCount;//次数累加
Group g = m.Groups[1];
m = m.NextMatch();
}
return matchCount;
}
}
else
{
return 0;
}