How to find the IP address if I know the network path

Just wonder if any one have the experience to do this.

Supposed that I have 2 kind of path:

string path1 = "\\machinename\path";
string path2 = "Y:\path";//Y is network drive

I need a function to do this

string ip1 = GetIP(path1);//ip1 needs to be the ip address of \\machinename
string ip2 = GetIP(path2);//ip2 needs to be the ip address of Y:

I could not find a good answer on Google search, can anyone give me a hint?

Thank you in advance.

Evan LiSr SW EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnBusiness Consultant (Owner)Commented:
Get PsExec from Microsoft SystInternals.

Open an admin command prompt.

psexec \\computer ipconfig
Tahir QureshiSystem AnalystCommented:
Ip is associated with MachinName.
When you mapped a network drive and assign a letter. letter will represent the network location (\\MachinName\FolderName)

so you will get the same result either you ping
ping MachinName


ping Y: (if Y: is mapped to to same host)

HostName = InputFile.ReadLine

Set WshShell = WScript.CreateObject("WScript.Shell")
IP = WshShell.Run("ping -n 1 " & HostName, 0, True)

Open in new window

Evan LiSr SW EngineerAuthor Commented:
Thank you John, I need a solution for c#.
Thank you Tahir, ping does not work for Y:, it need another way.
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

JohnBusiness Consultant (Owner)Commented:
PsExec is just a command shell. Find a command shell for C  and then enter \\computer ipconfig as the command. It will produce a result you can capture in your program.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I can only tell in general terms. If you have drive mapping, you need to get the associated UNC path (there should be Win32 API calls to do so, maybe even .NET methods).
From UNC, you need to extract the machine name (e.g. by parsing).
And with the machine name, you can do a Win32 call to gethostbyname with that name.

So your question consists actually of three different tasks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Olgierd UngehojerSenior Network AdministratorCommented:
ping machinename
Evan LiSr SW EngineerAuthor Commented:
I found that Win32 API WNetGetUniversalName can do it, Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.