I want to get client computer MAC address and IP at the time of login for purpose of uniquely identify the client computer.
To get the user's IP address you can use Request.UserHostAddress or Request.ServerVariables["REMOTE_ADDR"].
Getting the MAC address I am not sure it is so simple. It is not something that is available to the server (ASP.NET) like the IP address is. From what I know you will need to use client scripting and ActiveX or Java applets to get to that information (after multiple installation and security prompts on the users' machines).
So in other words, get IP address by Request.UserHostAddress. Avoid using MAC address and look for another solution if IP is not unique enough for your needs. Maybe combine it with browser User Agent string instead (Request.ServerVariables["HTTP_USER_AGENT"] or Request.UserAgent but the latter might not be available in older versions of .NET).
You can get client IP address from request objects UserHostAddress property like
Page.Request.UserHostAddress
Looks like there is no straight forward way of getting client MAC address except using WMI which other answers already have pointed on.
refer to the below link , may be they will be useful for you...
http://forums.asp.net/t/1911211.aspx?Get+Client+Mac+Address+in+Asp+Net+Web+Application
http://www.codeproject.com/Answers/187064/i-need-MAC-Address-of-client-machine-using-asp-net#answer1
I tried many solutions but i'm just getting mac address of the server. I need to get mac address of the client machine. Is this possible to get mac address of the client machine?
If not, is this possible to get any other unique id from client machine?
The short answer is: No
It is not possible to get the MAC address from the client using JavaScript as this will pose a serious security risk.
The only unique id you will be able to get is the IP address, but this will possibly not be unique as the user's machine might be NATed behind a router.
You could use an ActiveX control on Java applet to get the client machine's MAC address, but this would require installation of the chosen method on the client machine and will never be a fail-safe way of obtaining the MAC address.
I'm writing a program that is accessed from a local network and also from the outside. I have to identify local and outside requests in order to give different functionality to each. Is that possible?
An alternative is to document the IP addresses of all the local computers and to get the IP address of the client thru Request.ServerVariables["Remote_ADDRS"] and compare them, if the request IP address doesn't match that means the request is not local. That seems to be awkward and inefficient because I would have to save all local addresses and any new computer would have to be regestered.
Is there a simple way to identify if a request is coming from the local network or from the outside?
Thank you!
Your network administrator will be able to tell you the IP range of the internal network. Then you can simply check if the client IP falls into the internal range.
This way, you only need to change your configuration, when the internal ranges is changed. This should not happen too often.
Edit: Here is a question and answer about IP ranges (albeit in Java, but should be very simple to convert).
Are you on a domain with the internal users? If so you could just offer the internal functionality only to those who login with integrated authentication.
Using C# how would one determine if a URL is an intranet URL? I would like some code to do something if a URL is an intranet one vs public.
you cannot implicitely know. if your intranet urls look like fully qualified domain names then it's difficult to tell. the only way to tell is to query two different DNS-servers (your own and a public one). If both return the same result, then it's an internet domain. if the public DNS-server isn't able to resolve the address, then it's most likely an intranet domain.
Do you know the internal subnets (in terms of IP addresses)? If so, I'd just resolve the host name and see if it's internal that way.
if the url resolves to a tcpIp address which is one of the IP addresses set aside as a private IPAddress, then it is definitely on your Intranet. these are
10.xxx.xxx.xxx,
172.16.xxx.xxx through 172.31.xxx.xxx, and
192.168.xxx.xxx
if it resolves to any other IP address it might still be on your intranet, but it has a public IP address so it is potentially accessible from outside the Intranet
The simple, and not perfect but works for the 80% case is to simply check if the URL has a period in it. I know Intranet URLs can be fully qualified, but in my experience (at Microsoft) most do not, and this works pretty well.
In general, there is no reliable way to tell an intranet URL from an Internet URL. If the intranet is available to your program, then it will look just like the Internet, and if not, then you still won't know whether the URL is supposed to be a working intranet URL or is just a (temporarily) broken Internet URL.
You will need some special knowledge, such as the domain names or IPs of the servers that are providing the intranet, in order to tell them apart.
If you want to determine whether any given URL is an intranet url in any company (as opposed to specializing your code for one particular company), I wish you luck.
Usually, but not always, itranet urls do not have a TLD (Top Level Domain, such as .com). However, I've seen some that do.
Almost always (AFAIK), intranet domains will resolve to a similar IP address as the computer's current address. Note that I did not say the same subnet; large intranets can have multiple subnets. Also note that if the computer is not in a corporate intranet, there will be regualr domain names that resolve to similar IP addresses. (Unless the computer is behind NAT)
I am not a C# programmer, so I can't offer you code, but the basic method would involve comparing the hostname part of the URL to that of server(s) in your intranet. Or, if your URL just uses an IP not a DNS name, compare the IP to that of your intranet server(s).
Crack the URL using string manipulation - though I imagine C# must have a URL class that will do this for you - and extract the hostname, compare it to a list of servers.
You could interrogate internet explorer to see if the domain would match the list of accepted intranet domains.
Registry key is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
There if the domain has a value for 1 for the protocol it will be deemed an intranet domain. You'll need to perform a nslookup to gather the 'real' address.
To add to what others have said, Intranet do not have any of the know top-level domain in its address. I've worked in a few companies and all the Intranet were something like:
http://developments/admin - you will notice that there's no top-level domain at all. So, it resolves to a computer within the network. Again, as the name suggests, you are not likely to access it beyond the corporate environment.
I have web service on server! This service is calling from the clients applications!
Now how i can get user name and computer name of clients that using this service, for example if application from Clint1 calling this service i want to get computer name and user name of Clint1?
Many thanks!
You can't reliably, really.
The server variable REMOTE_HOST may provide you with it, but in most cases it will be an IP address and it could well be a proxy's IP address. Also - it is something that can be easily spoofed.
Same goes for username (REMOTE_USER), unless you use some WS-Security mechanism to authenticate the user calling your webservice.
The client will have to be passing this information to the service.
As Wim said, you can't get this information reliably. For a guaranteed Windows network you can retrieve the current authenticated user (to the machine) using the server variable:
System.Web.HttpContext.Current.Request.ServerVariables("LOGON_USER")
The REMOTE_HOST variable is supposed to return the machine name, but in most cases (as he said) it will only be an IP address.
Even on a LAN, this is not an advisable security practice. This information can still be spoofed locally providing internal users the capability to masquerade as other users. If it's simply being used for identification (rather than authentication or authorization) it would probably be "good enough". If you maintained a small datatable (or the networking team) that identified each pc to its expected IP address, this information would achieve what you want.