473,238 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

How to get local machine name and IP address?

Hi, here,
How to get local machine name and IP address?
Thanks.

Nov 29 '06 #1
5 72317
go to the command prompt (Start -Run -type "cmd")
at the prompt type "ipconfig"

"ipconfig/all" for more details.

for the computer name rightclick on MyComputer and go to properties,
then computer name.

ta-da.
Hooyoo wrote:
Hi, here,
How to get local machine name and IP address?
Thanks.
Nov 29 '06 #2

jayper wrote:
go to the command prompt (Start -Run -type "cmd")
at the prompt type "ipconfig"

"ipconfig/all" for more details.

for the computer name rightclick on MyComputer and go to properties,
then computer name.

ta-da.
Hooyoo wrote:
Hi, here,
How to get local machine name and IP address?
Thanks.
faint, I mean write codes to get that.

Nov 29 '06 #3
Environment.MachineName will return the local NetBios name as a string

you can also use:

System.Net.dns.GetHostName();

Getting the IP addresses is a little more tricky - as there can be more
than one per host name:

System.Net.IPAddress[] a =
System.Net.Dns.GetHostAddresses(System.Net.Dns.Get HostName());

for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i].ToString());
}

Hope this solves your problem

On Nov 29, 2:07 pm, "Hooyoo" <zhao_huy...@126.comwrote:
jayper wrote:
go to the command prompt (Start -Run -type "cmd")
at the prompt type "ipconfig"
"ipconfig/all" for more details.
for the computer name rightclick on MyComputer and go to properties,
then computer name.
ta-da.
Hooyoo wrote:
Hi, here,
How to get local machine name and IP address?
Thanks.faint, I mean write codes to get that.
Nov 29 '06 #4
Hi,

Use Environment.MachineName to get the local machine's NetBIOS name.

Here's some code that will get one of the IP addresses assigned to the local
computer, accounting for multiple network adapters and scope (e.g., LAN,
WAN):

public static class Network
{
#region DNS
public static IPAddress FindIPAddress(bool localPreference)
{
return FindIPAddress(Dns.GetHostEntry(Dns.GetHostName()),
localPreference);
}

public static IPAddress FindIPAddress(IPHostEntry host, bool
localPreference)
{
if (host == null)
throw new ArgumentNullException("host");

if (host.AddressList.Length == 1)
return host.AddressList[0];
else
{
foreach (System.Net.IPAddress address in host.AddressList)
{
bool local = IsLocal(address);

if (local && localPreference)
return address;
else if (!local && !localPreference)
return address;
}

return host.AddressList[0];
}
}

public static bool IsLocal(IPAddress address)
{
if (address == null)
throw new ArgumentNullException("address");

byte[] addr = address.GetAddressBytes();

return addr[0] == 10
|| (addr[0] == 192 && addr[1] == 168)
|| (addr[0] == 172 && addr[1] >= 16 && addr[1] <= 31);
}
#endregion
}

--
Dave Sexton

"Hooyoo" <zh*********@126.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
Hi, here,
How to get local machine name and IP address?
Thanks.

Nov 29 '06 #5
Thanks, got it.
ni***********@iinet.net.au wrote:
Environment.MachineName will return the local NetBios name as a string

you can also use:

System.Net.dns.GetHostName();

Getting the IP addresses is a little more tricky - as there can be more
than one per host name:

System.Net.IPAddress[] a =
System.Net.Dns.GetHostAddresses(System.Net.Dns.Get HostName());

for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i].ToString());
}

Hope this solves your problem

On Nov 29, 2:07 pm, "Hooyoo" <zhao_huy...@126.comwrote:
jayper wrote:
go to the command prompt (Start -Run -type "cmd")
at the prompt type "ipconfig"
"ipconfig/all" for more details.
for the computer name rightclick on MyComputer and go to properties,
then computer name.
ta-da.
Hooyoo wrote:
Hi, here,
How to get local machine name and IP address?
Thanks.faint, I mean write codes to get that.
Nov 29 '06 #6

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

Similar topics

2
by: Robin Tucker | last post by:
Hi, I would like to know the name of the local machine. At present I can use "(local)" for setting up database connections, but I would like a quick way of knowing that (local) = "RTUCKER" (for...
1
by: Chakravarti Mukesh | last post by:
Hi all, I need to know the IP address of the machine where the application is running. How can I get this? Thanks Chakravarti Mukesh
6
by: Michael | last post by:
I am running an application that requires "Full Trust" which is declared in the assembly. How do I trap for the System.Security.Policy.PolicyException that is raised by a local machines CAS if...
2
by: jayadevi | last post by:
Hi all, I have to get IP of the local machine. For ex:Using machine A , i have connected to another server(machine) B, in machine B i am browsing one asp page which gets the IP address using the...
7
by: Raju5725 | last post by:
Hi All, How can I Change Local Machine IP Address without rebooting the machine using VB.Net. As I want to shift from one IP address to another IP address with application the effect should...
5
by: sternchen | last post by:
Hello, I have a .NET application through which a user can select files. This happens through the OpenFileDialog. Now, I also need to know whether that file is on my local machine or from a server....
3
by: Al Reid | last post by:
I need a way to uniquely identify the machine, IP Address or user that called a web service. We are attempting to loosely integrate two applications where both apps, running on a single machine,...
2
by: jason | last post by:
Hello everyone, I am writing to discover if there is a way, through System libraries or some other method, to acquire the name of the local machine from within an object library DLL. In case...
4
by: supersav144 | last post by:
Hi there, i have a simple application which connects to a web service and then this web service creates a file on the machine which the application was accessed on... the problem i have though...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.