1. Cấu hình 1 card mạng như bình thường, chọn default gateway cho card mạng này.
2. Đối với card mạng nối WAN dùng lệnh(Giả sử mạng WAN này có IP dạng 192.168.x.x, gateway ra WAN là 192.168.1.250):
route add 192.168.0.0 MASK 255.255.0.0 192.168.1.250
Showing posts with label Network. Show all posts
Showing posts with label Network. Show all posts
12.1.10
16.10.08
Lấy IP ra Internet của máy đằng client
using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace DreamInCode.Snippets
{
public class IpFinder
{
public static IPAddress GetExternalIp()
{
string whatIsMyIp = "http://whatismyip.com";
string getIpRegex = @"(?<=<TITLE>.*)\d*\.\d*\.\d*\.\d*(?=<TITLE>)";
WebClient wc = new WebClient();
UTF8Encoding utf8 = new UTF8Encoding();
string requestHtml = "";
try
{
requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
}
catch (WebException we)
{
// do something with exception
Console.Write(we.ToString());
}
Regex r = new Regex(getIpRegex);
Match m = r.Match(requestHtml);
IPAddress externalIp = null;
if (m.Success)
{
externalIp = IPAddress.Parse(m.Value);
}
return externalIp;
}
}
}
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace DreamInCode.Snippets
{
public class IpFinder
{
public static IPAddress GetExternalIp()
{
string whatIsMyIp = "http://whatismyip.com";
string getIpRegex = @"(?<=<TITLE>.*)\d*\.\d*\.\d*\.\d*(?=<TITLE>)";
WebClient wc = new WebClient();
UTF8Encoding utf8 = new UTF8Encoding();
string requestHtml = "";
try
{
requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
}
catch (WebException we)
{
// do something with exception
Console.Write(we.ToString());
}
Regex r = new Regex(getIpRegex);
Match m = r.Match(requestHtml);
IPAddress externalIp = null;
if (m.Success)
{
externalIp = IPAddress.Parse(m.Value);
}
return externalIp;
}
}
}