Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2005

Tip: Looking for answers? Try searching our database.

IPAddress

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Cooper - 30 Sep 2005 17:45 GMT
Hi

Is there a class with a method in the .NET Framework that will verify if a
string is in the correct dotted format to be an IPAddress.  Similar to
inet_addr

nnn.nnn.nnn.nnn

Thank You
Mark
Jon Skeet [C# MVP] - 30 Sep 2005 17:50 GMT
> Is there a class with a method in the .NET Framework that will verify if a
> string is in the correct dotted format to be an IPAddress.  Similar to
> inet_addr
>
> nnn.nnn.nnn.nnn

Have you tried IPAddress.Parse?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Mark Cooper - 30 Sep 2005 18:20 GMT
Yes but I was hoping to check the string without having to add the overhead
of an exception.  The majority of the time it will be a DNS host name not an
IP address.
Jon Skeet [C# MVP] - 30 Sep 2005 18:46 GMT
> Yes but I was hoping to check the string without having to add the overhead
> of an exception.  The majority of the time it will be a DNS host name not an
> IP address.

When you talk about the overhead of the exception, just how many of
these are you doing? See
http://www.pobox.com/~skeet/csharp/exceptions.html

It would be reasonably easy to hard-code a test, and feasible to do as
a regular expression (the tricky bit is rejecting 300.300.300.300 but
allowing 30.30.30.255 etc). The *simplest* way is probably to use
IPAddress.Parse though. Whether this counts as an abuse of exceptions
is a matter of taste IMO. Note that in .NET 2 you'll be able to use
IPAddress.TryParse, which is much more what you're after.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Kevin Spencer - 30 Sep 2005 21:53 GMT
The 2.0 Platform has a TryParse for the IPAddress, and a number of other
classes as well. It doesn't throw an exception. Unfortunately, the 1.1
platform does not.

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Big things are made up of
lots of little things.

>> Yes but I was hoping to check the string without having to add the
>> overhead
[quoted text clipped - 12 lines]
> is a matter of taste IMO. Note that in .NET 2 you'll be able to use
> IPAddress.TryParse, which is much more what you're after.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.