473,405 Members | 2,210 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,405 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 72325
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.