473,666 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 72347
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.Mac hineName 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.IPAd dress[] a =
System.Net.Dns. GetHostAddresse s(System.Net.Dn s.GetHostName() );

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

Hope this solves your problem

On Nov 29, 2:07 pm, "Hooyoo" <zhao_huy...@12 6.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.Mac hineName 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(b ool localPreference )
{
return FindIPAddress(D ns.GetHostEntry (Dns.GetHostNam e()),
localPreference );
}

public static IPAddress FindIPAddress(I PHostEntry host, bool
localPreference )
{
if (host == null)
throw new ArgumentNullExc eption("host");

if (host.AddressLi st.Length == 1)
return host.AddressLis t[0];
else
{
foreach (System.Net.IPA ddress address in host.AddressLis t)
{
bool local = IsLocal(address );

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

return host.AddressLis t[0];
}
}

public static bool IsLocal(IPAddre ss address)
{
if (address == null)
throw new ArgumentNullExc eption("address ");

byte[] addr = address.GetAddr essBytes();

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

--
Dave Sexton

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

Nov 29 '06 #5
Thanks, got it.
ni***********@i inet.net.au wrote:
Environment.Mac hineName 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.IPAd dress[] a =
System.Net.Dns. GetHostAddresse s(System.Net.Dn s.GetHostName() );

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

Hope this solves your problem

On Nov 29, 2:07 pm, "Hooyoo" <zhao_huy...@12 6.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
3702
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 instance). I can't find a machine name on the application object, but I'm sure its probably easily accessable from somewhere. Thanks,
1
1755
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
1909
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 its current policy will not allow "Full Trust", ie its running in the Intranet Zone. I am trying to trap the error to advise users to have adm revise policy to permit running the program otherwise a cryptic debug screen is raised.
2
7984
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 code Request.ServerVariables("remote_addr") which returns the IP of machine B. But I want to write a asp code which gets the IP address of machine A.
7
14506
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 take place without rebooting the system. Thanks in advance. Raju
5
1971
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. How can I find out the exact machine name from where the file is loaded, so that i can compare that with my local machine name later? cheers, sternchen
3
4301
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, will call a web service to communicate a few simple tokens. The problem is that there can be multiple users on different PC's using the system and I need to save the source of the token so that it is picked up by the correct machine. One of the...
2
1619
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 it is relevant, I have an object library DLL that performs a generic "error handling" process for each exception that is thrown by either itself, or by an application that is using the DLL. One of the pieces of information that the generic error...
4
2135
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 is that when i use the web service im not sure how i need to or the format to refer to the local machine (i.e do i use machine name, the IP address??) in order to save the file to this local machine. Any help would be much appreciated! Phil
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.