Subversion Repositories general

Rev

Rev 1197 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1194 dev 1
using System;
2
using System.Collections.Generic;
3
using System.Net;
4
using System.Text;
5
using System.Text.RegularExpressions;
6
 
7
namespace TCPproxy
8
{
9
	abstract class HostUtils
10
	{
11
		public static IPAddress ResendHostToIp(string host)
12
		{
13
			IPAddress ip;
14
 
15
			if(host == "")
16
			{
17
				throw new Exception("Please enter the resend host");
18
			}
19
 
20
			Regex ipRegex = new Regex(@"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$");
21
			if(ipRegex.Match(host).Success)
22
			{
23
				try
24
				{
25
					ip = IPAddress.Parse(host);
26
				}
27
				catch(FormatException)
28
				{
29
					throw new Exception("Wrong IP address of the resend host");
30
				}
31
			}
32
			else
33
			{
34
				IPHostEntry hostInfo = Dns.GetHostEntry(host);
35
 
36
				if(hostInfo.AddressList.Length > 0)
37
				{
38
					ip = hostInfo.AddressList[0];
39
				}
40
				else
41
				{
42
					throw new Exception("Cannot find IP address of the resend host");
43
				}
44
			}
45
 
46
			return ip;
47
		}
48
	}
49
}