473,498 Members | 37 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

host ...

In my App the user could manually enter some host computer location
for this he has the choice to enter either the IP or host name.
I get the IP address internally with the following code sample:
IPAddress ia;
try
{
ia = IPAddress.Parse(host);
}
catch(FormatException)
{
IPHostEntry he = Dns.GetHostByName( host );
ia = he.AddressList[0];
}
I wonder if there is another way to do that which would avoid the try catch,
any tips ?
Nov 15 '05 #1
5 1285
Hi Lloyd,

Thanks for posting to the newsgroup.

You could potentially run this through a regular expression to see if it's
in the right format for either a machine name or an IP address and then use
the appropriate method -- Parse() or GetHostByName(). I'd still use the try
/ catch block in case there are any problems you miss.

Hope this helps,
bliz

--
Jim Blizzard, MCSD .NET
Community Developer Evangelist | http://www.microsoft.com/communities
Microsoft

Your Potential. Our Passion.

This posting is provided as is, without warranty, and confers no rights.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
In my App the user could manually enter some host computer location
for this he has the choice to enter either the IP or host name.
I get the IP address internally with the following code sample:
IPAddress ia;
try
{
ia = IPAddress.Parse(host);
}
catch(FormatException)
{
IPHostEntry he = Dns.GetHostByName( host );
ia = he.AddressList[0];
}
I wonder if there is another way to do that which would avoid the try catch, any tips ?

Nov 15 '05 #2
well you agree me ;-)
I though my code was ok, but I read on many thread recently than one should
prefer erro code to try catch as a program logic as it has really bad
performance impact.

anyway this parsing is done but a few times, so that should be ok ...

"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message
news:3f********@news.microsoft.com...
Hi Lloyd,

Thanks for posting to the newsgroup.

You could potentially run this through a regular expression to see if it's
in the right format for either a machine name or an IP address and then use the appropriate method -- Parse() or GetHostByName(). I'd still use the try / catch block in case there are any problems you miss.

Hope this helps,
bliz

--
Jim Blizzard, MCSD .NET
Community Developer Evangelist | http://www.microsoft.com/communities
Microsoft

Your Potential. Our Passion.

This posting is provided as is, without warranty, and confers no rights.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
In my App the user could manually enter some host computer location
for this he has the choice to enter either the IP or host name.
I get the IP address internally with the following code sample:
IPAddress ia;
try
{
ia = IPAddress.Parse(host);
}
catch(FormatException)
{
IPHostEntry he = Dns.GetHostByName( host );
ia = he.AddressList[0];
}
I wonder if there is another way to do that which would avoid the try

catch,
any tips ?


Nov 15 '05 #3
You are right about that. I hope MS provides a non-exception way to do
Parsing sometime... :). If you're worried about performance, then running
some basic tests can help prevent some exceptions being thrown. If it's not
going to happen often, then don't even worry about it.
-mike
MVP

"Lloyd Dupont" <net.galador@ld> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
well you agree me ;-)
I though my code was ok, but I read on many thread recently than one should prefer erro code to try catch as a program logic as it has really bad
performance impact.

anyway this parsing is done but a few times, so that should be ok ...

"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message
news:3f********@news.microsoft.com...
Hi Lloyd,

Thanks for posting to the newsgroup.

You could potentially run this through a regular expression to see if it's in the right format for either a machine name or an IP address and then

use
the appropriate method -- Parse() or GetHostByName(). I'd still use the

try
/ catch block in case there are any problems you miss.

Hope this helps,
bliz

--
Jim Blizzard, MCSD .NET
Community Developer Evangelist | http://www.microsoft.com/communities
Microsoft

Your Potential. Our Passion.

This posting is provided as is, without warranty, and confers no rights.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
In my App the user could manually enter some host computer location
for this he has the choice to enter either the IP or host name.
I get the IP address internally with the following code sample:
IPAddress ia;
try
{
ia = IPAddress.Parse(host);
}
catch(FormatException)
{
IPHostEntry he = Dns.GetHostByName( host );
ia = he.AddressList[0];
}
I wonder if there is another way to do that which would avoid the try

catch,
any tips ?



Nov 15 '05 #4
> I wonder if there is another way to do that which would avoid the try
catch,
any tips ?


You could always use the Dns.GetHostByName method, it suports both hostname
and IP address. If you pass it a name (e.g. "www.google.com"), it will
resolve the address. If you pass it an IP address (e.g. "216.239.41.99"), it
will just parse that and return it as the address.

Hope this helps,
-JG
Nov 15 '05 #5
ho, cool ....
I will use that for my apps.

anyway on pocket pc I had some bad experience with Dns.GetHostByName()

"Juan Gabriel Del Cid" <jd*****@atrevido.nospam.net> wrote in message
news:eh**************@TK2MSFTNGP10.phx.gbl...
I wonder if there is another way to do that which would avoid the try catch,
any tips ?


You could always use the Dns.GetHostByName method, it suports both

hostname and IP address. If you pass it a name (e.g. "www.google.com"), it will
resolve the address. If you pass it an IP address (e.g. "216.239.41.99"), it will just parse that and return it as the address.

Hope this helps,
-JG

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
11118
by: jason mazzotta | last post by:
Hi, I'm rather new to both MySQL and PHP. I've been trying to use PHP to write to a MySQL database. I call mysql_pconnect to get a database connection, but then when I call mysql_db_select, I get...
9
3323
by: Jeff | last post by:
Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For example if I type HostName.domain.com in my browser I want to return it exactly as it appears in the location part of the browser...
1
2275
by: Dave | last post by:
I know that Remoting requires a host application on the server. Is it possible to use COM+ as the host? If so, where can a good example be found?
6
1899
by: Tim | last post by:
I am in the process of moving a site from one hosting company to another. This site is fairly large, with hundreds of asp files, each with multiple "include" statements. The new host has a...
3
3007
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements -...
2
2179
by: Jeff | last post by:
I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in the eNPTest02 directory of my localhost on my development machine. The database is on the web. ...
6
2651
by: Brian Henry | last post by:
is there a way to get the host name of someone? like mine is 68-23-123-123-pitt-pa.adelphia.net? Request.UserHostName doesn't seem to return the host name like it states in the documentation,...
5
4739
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
7
13661
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
5
1586
by: Krice | last post by:
There is a component class inside the host class: class Host { Component *c; .... In some cases Component needs to call the host and I guess the only way is that you pass the host for it:
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.