Convert from network name to ip address

I have a function that reads a file but fails if I pass it a network device 
name instead of an ip address eg:-

ReadFunction("\\NAS\Myfolder\Myfile.txt")  <--- Fails
ReadFunction("\\192.168.2.2\Myfolder\Myfile.txt")  <--- Works

So how do I convert a network devices name to it's ip address?
ie. Convert \\NAS\ to \\192.168.2.2\

Thanks
Robert


 

0
Roidy
5/31/2010 12:56:40 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

6 Replies
1442 Views

Similar Articles

[PageSpeed] 46

Am 31.05.2010 14:56, schrieb Roidy:
> I have a function that reads a file but fails if I pass it a network device 
> name instead of an ip address eg:-
> 
> ReadFunction("\\NAS\Myfolder\Myfile.txt")  <--- Fails
> ReadFunction("\\192.168.2.2\Myfolder\Myfile.txt")  <--- Works
> 
> So how do I convert a network devices name to it's ip address?
> ie. Convert \\NAS\ to \\192.168.2.2\


Try this:  (passing "NAS")

  System.Net.Dns.GetHostByName(ByVal String) As System.Net.IPHostEntry

Does it fail, too?


-- 
Armin
0
Armin
5/31/2010 2:58:33 PM
Thanks Armin,

VB complains that GetHostByName is obsolete and tells you to use 
GetHostEntry, which works perfectly:-

Dim hostname As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("NAS")
Dim ipaddress() As System.Net.IPAddress = hostname.AddressList

Now it just an easy task to write a function to strip out the network device 
name from the path and replace it with the resulting IP address.

Thanks
Robert


"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:eoljMHNALHA.348@TK2MSFTNGP06.phx.gbl...
> Am 31.05.2010 14:56, schrieb Roidy:
>> I have a function that reads a file but fails if I pass it a network 
>> device
>> name instead of an ip address eg:-
>>
>> ReadFunction("\\NAS\Myfolder\Myfile.txt")  <--- Fails
>> ReadFunction("\\192.168.2.2\Myfolder\Myfile.txt")  <--- Works
>>
>> So how do I convert a network devices name to it's ip address?
>> ie. Convert \\NAS\ to \\192.168.2.2\
>
>
> Try this:  (passing "NAS")
>
>  System.Net.Dns.GetHostByName(ByVal String) As System.Net.IPHostEntry
>
> Does it fail, too?
>
>
> -- 
> Armin
> 
0
Roidy
5/31/2010 3:55:29 PM
This is what I knocked together to check the path to see if it's network 
path and then replace the device name with it's IP address. Seems to work, 
can you see any problems I might face using this? or is there a better way?

Public Function PathFixer(ByVal path As String) As String
        If path.StartsWith("\\") Then  ' Check to see if it's a network path
            Dim output As String
            Dim splits() As String = path.Substring(2, path.Length - 
2).Split("\")
            Dim hostname As System.Net.IPHostEntry = 
System.Net.Dns.GetHostEntry(splits(0))
            Dim ips() As System.Net.IPAddress = hostname.AddressList
            output = path.Remove(2, splits(0).Length)
            Return output.Insert(2, ips(0).ToString)
        Else
            Return path
        End If
End Function

Thanks
Robert

"Roidy" <roidy.parnell@ntlworld.com> wrote in message 
news:0_QMn.5693$QF7.3830@hurricane...
> Thanks Armin,
>
> VB complains that GetHostByName is obsolete and tells you to use 
> GetHostEntry, which works perfectly:-
>
> Dim hostname As System.Net.IPHostEntry = 
> System.Net.Dns.GetHostEntry("NAS")
> Dim ipaddress() As System.Net.IPAddress = hostname.AddressList
>
> Now it just an easy task to write a function to strip out the network 
> device name from the path and replace it with the resulting IP address.
>
> Thanks
> Robert
>
>
> "Armin Zingler" <az.nospam@freenet.de> wrote in message 
> news:eoljMHNALHA.348@TK2MSFTNGP06.phx.gbl...
>> Am 31.05.2010 14:56, schrieb Roidy:
>>> I have a function that reads a file but fails if I pass it a network 
>>> device
>>> name instead of an ip address eg:-
>>>
>>> ReadFunction("\\NAS\Myfolder\Myfile.txt")  <--- Fails
>>> ReadFunction("\\192.168.2.2\Myfolder\Myfile.txt")  <--- Works
>>>
>>> So how do I convert a network devices name to it's ip address?
>>> ie. Convert \\NAS\ to \\192.168.2.2\
>>
>>
>> Try this:  (passing "NAS")
>>
>>  System.Net.Dns.GetHostByName(ByVal String) As System.Net.IPHostEntry
>>
>> Does it fail, too?
>>
>>
>> -- 
>> Armin
>>
> 
0
Roidy
5/31/2010 4:18:56 PM
Am 31.05.2010 17:55, schrieb Roidy:
> Thanks Armin,
> 
> VB complains that GetHostByName is obsolete and tells you to use 
> GetHostEntry, which works perfectly:-
> 
> Dim hostname As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("NAS")
> Dim ipaddress() As System.Net.IPAddress = hostname.AddressList
> 
> Now it just an easy task to write a function to strip out the network device 
> name from the path and replace it with the resulting IP address.

Yes, sorry, you're right. Didn't try it and didn't see the warning.

-- 
Armin
0
Armin
6/1/2010 7:02:06 AM
Am 31.05.2010 18:18, schrieb Roidy:
> This is what I knocked together to check the path to see if it's network 
> path and then replace the device name with it's IP address. Seems to work,
> can you see any problems I might face using this? or is there a better way?

If it works fine for you, it's ok. :-) Though I wonder why your "ReadFunction"
works with the IP but not with the host name, while resolving the host name
before using GetHostEntry seems to work. What does 'ReadFunction" do with
the string? Apart from this:

- A possible problem is that the host name can not be resolved. I can't test
the situation because my provider seems to redirect all unknown host names to
the same IP.
- always enable Option Strict
- make the function Shared


> Public Function PathFixer(ByVal path As String) As String
>         If path.StartsWith("\\") Then  ' Check to see if it's a network path
>             Dim output As String
>             Dim splits() As String = path.Substring(2, path.Length - 
> 2).Split("\")
>             Dim hostname As System.Net.IPHostEntry = 
> System.Net.Dns.GetHostEntry(splits(0))
>             Dim ips() As System.Net.IPAddress = hostname.AddressList
>             output = path.Remove(2, splits(0).Length)
>             Return output.Insert(2, ips(0).ToString)
>         Else
>             Return path
>         End If
> End Function

-- 
Armin
0
Armin
6/1/2010 7:19:04 AM
Unfortunately the readfunction isn't mine it's the MP4Read function from 
libmp4v2.dll so I'm not sure why it only works with IP addresses and not 
host names. Your right I should really do some error checking because if 
GetHostEntry fails to resolve the host name it throws an exception.

Thanks
Robert


"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:uZtkqrVALHA.1448@TK2MSFTNGP06.phx.gbl...
> Am 31.05.2010 18:18, schrieb Roidy:
>> This is what I knocked together to check the path to see if it's network
>> path and then replace the device name with it's IP address. Seems to 
>> work,
>> can you see any problems I might face using this? or is there a better 
>> way?
>
> If it works fine for you, it's ok. :-) Though I wonder why your 
> "ReadFunction"
> works with the IP but not with the host name, while resolving the host 
> name
> before using GetHostEntry seems to work. What does 'ReadFunction" do with
> the string? Apart from this:
>
> - A possible problem is that the host name can not be resolved. I can't 
> test
> the situation because my provider seems to redirect all unknown host names 
> to
> the same IP.
> - always enable Option Strict
> - make the function Shared
>
>
>> Public Function PathFixer(ByVal path As String) As String
>>         If path.StartsWith("\\") Then  ' Check to see if it's a network 
>> path
>>             Dim output As String
>>             Dim splits() As String = path.Substring(2, path.Length -
>> 2).Split("\")
>>             Dim hostname As System.Net.IPHostEntry =
>> System.Net.Dns.GetHostEntry(splits(0))
>>             Dim ips() As System.Net.IPAddress = hostname.AddressList
>>             output = path.Remove(2, splits(0).Length)
>>             Return output.Insert(2, ips(0).ToString)
>>         Else
>>             Return path
>>         End If
>> End Function
>
> -- 
> Armin
> 
0
Roidy
6/1/2010 9:34:59 AM
Reply:

Similar Artilces:

How to Convert UTC to localTIme(C# )
I have got the value of user account's lastlogon time. Its type is Int64. This value is stored as a large integer that represents the number of 100 nanosecond intervals since January 1, 1601 (UTC)(Refer to MSDN). I don't know how to convert this value to localTime. The following is my code. ################################################################ DirectoryEntry deUser = new DirectoryEntry(ldappath); DirectorySearcher src = new DirectorySearcher(deUser); src.Filter = "(&(objectClass=user)(SAMAccountName=" + accountNa...

a program is trying to acess e-mail address that you have stored in Outlook
ken@reidprogreaphics.com <anonymous@discussions.microsoft.com> wrote: Is there a question here somewhere? -- Brian Tillman ...

The underlying connection was closed: The remote name
Hi, I'm new to MS-CRM and am trying to get some given examples working. I've written the code to create a Business hierarchy. I'm getting the following error when I try to execute the code """"The underlying connection was closed: The remote name could not be resolved."""" Any suggestions or ways to resolve this would be of great help. Regards, Joan Joan, did you simply copied and pasted the sample code into your ASP.NET Web application? string strServer = "myservername"; Check if you assigned the strServer variable the...

Convert text to time value
I have a series of time values in a 'General' format. They are of the type: 184525 Which is 18:45:25 or 6:45:25 pm. A time which is am would be of the type: 12345 Which is 1:23:45 am. Is there a way to convert those 'General' values to an Excel serial so that I can figure out the difference between two times? I've seen a bunch of examples on the net, but none of those that I have found deal with this format that I can tell. Thanks. Hi try =--TEXT(A1,"00:00:00") -- Regards Frank Kabel Frankfurt, Germany "Andy" <amelton@gmail.com> schrieb...

how to convert date
Hi, I'm looking for some method to convert mail date, in format: eg. "Sun, 18 Sep 2005 20:57:08 +0200", to computer local time. I tried CTime but without resoults. m. Have you tried COleDateTime::ParseDateTime()? m.wski21.usunto@aust.com wrote: > Hi, > > I'm looking for some method to convert mail date, in format: > eg. "Sun, 18 Sep 2005 20:57:08 +0200", to computer local time. > I tried CTime but without resoults. > > m. >I'm looking for some method to convert mail date, in format: >eg. "Sun, 18 Sep 2005 20:57:08 +0200&qu...

Excel: Auto converting text to numbers
I am downloading an Excel sheet, and the numbers come in as text. It basically comes in as "33 %" but Excel registers this as text, not a percentage. I have a cell that will be used to add the numbers, but since they are text it doesn't work. Given this information, is there a way to convert the imported data into numbers. I would prefer to include this into my formula. The potential numbers are: 0, 1, 2, 3, 4, 0 %, 25 %, 33 %, 50 %, 67 %, 75 %, 100 %, and N/A I would prefer a function, again if possible, that could convert any number. Please note, the space between the nu...

naming convention for PNG resources?
So IDB_xxx is for bitmaps, IDS_xxx is for strings, etc. Is there one for PNGs? I know MFC doesn't support PNG "as is". I thought about IDP_xxx but thats taken. IDPNG_xxx or ID_PNG_xxx seems weird. Invent one. Why is IDPNG_ unacceptable? The names are arbitrary. joe On Sun, 16 Dec 2007 21:30:14 -0800, "Somebody" <somebody@cox.net> wrote: >So IDB_xxx is for bitmaps, IDS_xxx is for strings, etc. Is there one for >PNGs? I know MFC doesn't support PNG "as is". I thought about IDP_xxx but >thats taken. IDPNG_xxx or ID_PNG_xxx seems w...

How do I convert dates to text keeping the format?
I'm trying to convert a column of data in date format *m/d/yyyy to a text format without converting to serial numbers. Ie: I want to retain the mm/dd/yyyy format. Is there a way to do this? =TEXT(A1,"MM/DD"/YYYY") "sprlarry" <sprlarry@discussions.microsoft.com> wrote in message news:69669AA6-FD15-47D7-843D-FC768728BF7A@microsoft.com... > I'm trying to convert a column of data in date format *m/d/yyyy to a text > format without converting to serial numbers. Ie: I want to retain the > mm/dd/yyyy format. Is there a way to do this? That ...

how do you add names on a bubble chart?
hi does anyone know how to add names on a bubble chart? In article <D3AD4FAC-A0D3-4C77-AF73-72313357E6CF@microsoft.com>, Ravi@discussions.microsoft.com says... > hi does anyone know how to add names on a bubble chart? > What do you mean by "names?" Series names? Chart or axis title? Data labels? Custom text? Something else? -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions I bet he wants custom data labels. Here are two great (and free!) utilities for labeling Excel charts: Rob Bo...

how to convert excel's .cvf file to .csv file
...

Convert Access97 to 2000
Hello, we're currently running access97 and would like to convert it to 2000, but we don't know what is the administrator password for this database. Also this database is running on multi user and have difference permission for diffence users. Could someone help me how to do make this happen but keep the currently permission retaint. Thanks ...

Convert 2000 Calendar to web page
Greetings, When I convert my calendar for 2005 to a webpage, the page is off by 1 day. Is there a template or fix available to fix this? Thanks, Duane I can edit the html file but this should not be the case. Fixes? Suggestions...other than use Apple? "Duane Perry" <dlp_sr@yahoo.com> wrote in message news:yZRtd.5561$0r.1710@newsread1.news.pas.earthlink.net... > Greetings, > > When I convert my calendar for 2005 to a webpage, the page is off by 1 day. > Is there a template or fix available to fix this? > > Thanks, > > Duane > > Duane, ...

XML Note convert to DataSet
Hello, I have this function: object acmResponse = acmLogin.acmString("4001", "", paramFormLogin + paramUserBasics);System.Xml.XmlNode[] acmNodes = (System.Xml.XmlNode[])acmResponse; What I have todo, to convert the XML Object in the DataSet Object? Thank you Matthias ...

Convert
Is it possible to convert a Money file created in the USA version to that of the UK version? Thanks in advance The general way is QIF Export then Import. It's involved and has limitations like loan accounts don't QIF. See http://www.bollar.org/msmoney/#Q1. "Crispy" <nowayspammers@hotmail.com> wrote in message news:uQKSfzfyDHA.2500@TK2MSFTNGP09.phx.gbl... > Is it possible to convert a Money file created in the USA version to that of > the UK version? ...

Problem converting from Quicken to M2005
My Quicken files are mostly investment related, and generally converted fine. However all bonds (regular and muni's) converted as Investment type: Mutual Fund, not Bond. (1) How do I prevent that, (2) How do you change the Investment Type for an item? Thank you. In microsoft.public.money, Mike wrote: >My Quicken files are mostly investment related, and generally >converted fine. However all bonds (regular and muni's) converted as >Investment type: Mutual Fund, not Bond. (1) How do I prevent that, (2) Money typically converts custom data types from Quicken into funds. I thou...

Numbers converting to decimal
I a trying to figure out why when I type 11 and automatically converts it to .11, if I type 11. it will stay 11,if I change all the cells to text then back to number they willstay. I have checked the formatting of the cells, it even happens when I open a brand new worksheet. Any ideas? Thanks Dawn Hi Dawn, Tools>Option>Edit, uncheck Fixed Decimal -- Kind Regards, Niek Otten Microsoft MVP - Excel "DawnP" <anonymous@discussions.microsoft.com> wrote in message news:c3cf01c48a05$d75359d0$a501280a@phx.gbl... > I a trying to figure out why when I type 11 and &...

Converting Quicken 2004 to Money
Quicken 2004 has many bugs, and I have had it. The most recent being that it doesn't work AT ALL now that it is the year 2004. I have had to change the date on my computer today to open it. I want to get Money instead, however I do not know if Money can get my data from the 2004 version. Does anybody know for sure? Yes is the answer to the question you posed. No is the answer to the question you are getting to but didn't pose. M04 imports Q03 and earlier. If the past predicts the future M05 will import Q04. "Colin" <anonymous@discussions.microsoft.com> wrote ...

Converting from AOL to Outlook
Is there an efficient way for me to convert my AOL address book over to Outlook? Before I buy Outlook, I want to be sure I cam make the conversion without loosing the large address book I have on AOL. "Herb Clader" <Herb Clader@discussions.microsoft.com> wrote in message news:44A9739C-A94F-49AB-BF08-31D78A86CCB7@microsoft.com... > Is there an efficient way for me to convert my AOL address book over to > Outlook? > > Before I buy Outlook, I want to be sure I cam make the conversion without > loosing the large address book I have on AOL. AOL's help p...

Customizing "Convert Campaign Response"
We have created custom Fields in the Campaign Response entity that we would like to populate on the Lead Entity when we do a conversion. However it doesn't seem like this is possible from the Data Map. Is there a way to modify what fields are carried forward during a conversion, or do I need to find a different method? Thank you in advance. Hi, As I had some time left, I tried to figure this one out. To my surprise I can't find ANY direct link between a converted campaign response and a new lead. There is only an indirect link, through the campaign entity. But that does not ...

drag/drop files with different name
I have a CListCtrl which contains a list of files from a directory tree. I have it so that you can drag-and-drop files from the list into an Explorer Window, and files get copied just fine. What I would like to do is rename the destination file. So if F:\foo\bar.txt is dragged on to the Desktop, I'd figure out that it should be called qux.txt instead, and that's what should appear on the Desktop. Is there a way of munging my data source object? Should I try to find the drop destination instead, and try to rename it there? Any help is appreciated. Thanks, Gopi. -- Gopi Sundaram ...

Convert English language document to Hindi
Is there any software available to convert an English language text document to Hindi language document by using dictionary based translation (not transliteration). For example: The sentence : My name is Joseph Should be converted to : ???? ??? ????? ?? ...

Problem with AFX_THREAD_STATE class converting from VS6.0 to VS.NET 2003
I have inherited some code that works in VS6.0. It has code snippets like the following: _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); pThreadState->m_nLastHit = 0; and _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); CToolTipCtrl* pToolTip = pThreadState->m_pToolTip; It then does things with these values. In VS.NET, there is no member variable in _AFX_THREAD_STATE that corresponds to m_nLastHit or m_pToolTip. Have these been replaced by something similar in VS.NET 2003 that I can use? #if (_MFC_VER < 0x0700) _AFX_THREAD_STATE* pThreadState = AfxGetThrea...

Program trying to access e-mail addresses #3
I hope you can help me. When I need to forward an email, the following message appears: - "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "No". Yes No Help" Our IT Dept have run a virus check and there are no viruses. Would appreciate any suggestions on how to stop this message appearing each time I try to create a new email and each time when I wish to on-forward an email sent to me. Many thanks Ruth Stevens Ruth Stevens <anonymous@...

Address Book ???
Hello everyone, I'm using MS Outlook that I installed from the Microsoft office 2000 cd. I would like to know how I can save the address book in case my hard drive fails and need to restore my address book back into a re-installation of Outlook. Thanks to all who reply, Ismael Take a look here, it may help: http://www.slipstick.com/config/backup.htm --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching g...

Converting Hours an minutes just into minutes #2
Is thier a formula to use to change hous and minutes, just into minutes ex: 01:30 (1 hour and 30 minutes) into 90 minutes. And how do you format the cells. Thank you Select the cell and change the format to: [m] -- Gary's Student "Six Sigma Blackbelt" wrote: > Is thier a formula to use to change hous and minutes, just into minutes ex: > 01:30 (1 hour and 30 minutes) into 90 minutes. And how do you format the > cells. > > Thank you ...