Sounds like a good idea. I will add a check for valid chars.

IPAddress.Parse supports IP v4 and v6 addresses in the following
formats:

IP v4 addresses can be represented as quads of decimal, hex or octal
numbers, for example:

255.255.255.255
0xff.0xff.0xff.0xff
0Xfd.0Xfd.0Xfd.0Xfd
0377.0377.0377.0377

IP v6 addresses as colon separated hex values, for example:

0:0:0:0:0:0:0:1
1111:2222:3333:4444:5555:6666:123.123.123.123%1234567890
fe80::1:1:1:1%4
FF02:0:0:0:0:0:0:2
FF02::2

You will need to install the IPv6 protocol on the local network adapter
before IPAddress.Parse will support IP v6 addresses. IPAddress does not
support v6 addresses with subnets, i.e. with a '/' e.g.
"2002:e005:607::1/48".

The chars that I think are valid in an IP address string are:

0123456789abcdefABCDEFxX.:%

Does anyone know of any other chars that are valid in an IPAddress?

Nicko

> -----Original Message-----
> From: Mike Blake-Knox [mailto:[EMAIL PROTECTED] 
> Sent: 15 February 2005 14:21
> To: Log4NET Dev
> Subject: Minimizing IPAddress conversion exceptions
> 
> My normal practice is to do development testing of my 
> application with the Visual Studio debugger set so that 
> exceptions break into the debugger. I found that the format 
> exceptions when I used a hostname (instead of IP address) as 
> the UdpAppender's destination were distracting.
> 
> I have an optimization that bypasses the attempted conversion 
> from a dotted decimal formatted IP address if the string 
> contains anything other than a digit or decimal point.  In 
> case it's of interest the affected lines of 
> IPAddressConverter.cs (starting at line 79) are:
> 
> if (str.Trim("0123456789.".ToCharArray()).Length == 0) // 
> avoid expense of exception handling // if it's definitely NOT 
> an IP address { try { return IPAddress.Parse(str); }
> catch(FormatException)
> {
> // Ignore a FormatException, try to resolve via DNS }
> 
> 
> --
> Mike Blake-Knox
> 

Reply via email to