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" <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>
|