• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 45
  • Last Modified:

Need to gather FQDN from users

I need to collect from specific users FQDN. It is Intranet and we will set up the webpage, preferable in asp.net with vb
where the user will login and I will send to DB theirs FQDN
We collect it to prevent certain updates till it's time.
0
LessIsMore
Asked:
LessIsMore
  • 9
  • 7
2 Solutions
 
OriNetworksCommented:
Do you mean fqdn of their computer? You could use UserHostName
https://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostname.aspx
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
FQDN isn't all that reliable.  I say that because depending on the size of your company you can have NATs in the way which might prevent you from achieving what you're looking for.

Let's also say user1 logs in, performs an update from 1 computer, and the update happens.
User1 then travels to a different location, logs in, and performs the update.  The user experience will be different based on the user's location.

You're much better off tying the users to some kind of group, and driving your logic off the groups.
0
 
LessIsMoreAuthor Commented:
OnNetworks,
Can you elaborate a little, give an example how to use it on page?
Kyle,
It's temporary measure until we will find better solution. We have a national operations and need a quick list of computer that needs to be protected from certain update.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
OriNetworksCommented:
In VB.NET
Dim hostname as String = Server.HtmlEncode(Request.UserHostName)

Open in new window


In C#
String hostname = Server.HtmlEncode(Request.UserHostName);

Open in new window


As Kyle mentioned, this method(via web) of acquiring hostnames isn't that reliable, and can sometimes contain the IP address only.
0
 
LessIsMoreAuthor Commented:
yes, I tried to do it and it has only IP address.
I am not sure what else can I do since I was told to get FQDN not IP address.
Not sure about Kyle's logic to say the honest.
0
 
OriNetworksCommented:
If all machines are internal you should be able to do lookup the name by DNS assuming they are registered/setup with DHCP although I would test this thoroughly. I think this is as close as you can get with a web form.

Public Function GetHostNameFromIP(ByRef IP As String) As String 
    Dim host As System.Net.IPHostEntry        
     host = System.Net.Dns.GetHostByAddress(IP)  
     return host.HostName  
End Function 

Open in new window

0
 
LessIsMoreAuthor Commented:
OnNetwork, thanks for helping me. I cannot figure out how to gather the result to sql server. I cannot even see if I have results, I tried Response.Write, Console.Write and it does not display the result of the function.
Can you help with that?
0
 
OriNetworksCommented:
I've changed things around a bit. Since we know UserHostName is not reliable I've switched it to UserHostAddress since we only really need to resolve the ip address. If you pass that value to the function I gave you, it will return a string. If you use this code in your Page_Load, it should write to the top of the page "Resolved Hostname is:[ComputerName]". If it only writes "Resolved Hostname is:" then you're out of luck because not even resolving the name works in your situation


'put this in Page_Load
Response.Write("Resolved Hostname is:" & GetHostName())


'put this with the rest of your functions
Public Function GetHostName() As String 
    String ipAddress = Server.HtmlEncode(Request.UserHostAddress)
    Dim host As System.Net.IPHostEntry        
     host = System.Net.Dns.GetHostEntry(ipAddress )  
     return host.HostName  
End Function 

Open in new window

0
 
LessIsMoreAuthor Commented:
I get BC30109: 'String' is a class type and cannot be used as an expression.
on line 7
0
 
OriNetworksCommented:
I corrected my declaration of string. That's what i get for working c# and vb.net at the same time.

'put this in Page_Load
Response.Write("Resolved Hostname is:" & GetHostName())


'put this with the rest of your functions
Public Function GetHostName() As String 
    Dim ipAddress As String = Server.HtmlEncode(Request.UserHostAddress)
    Dim host As System.Net.IPHostEntry        
     host = System.Net.Dns.GetHostEntry(ipAddress )  
     return host.HostName  
End Function 

Open in new window

0
 
LessIsMoreAuthor Commented:
Sorry, I get blank page, nothing, nada.

Below is what I get response for. Unfortunately Computer name is the name of my server.
I will go with IP address and will match it to DNS. It complicates things since we do not have static IP addresses.
FQDN would be better.
Dim hostname As String = Server.HtmlEncode(Request.UserHostName)
   
    Response.Write("IP Address is " & hostname & " ")
       
Dim IPAddress As String

    IPAddress = Dns.GetHostName()
   
    Response.Write("ComputerName is " & IPAddress)
     
Dim ip As String = Request.ServerVariables("REMOTE_ADDR")
    Response.Write("IP address " & ip)
0
 
OriNetworksCommented:
If FQDN is absolutely required would deploying some kind of small application or script be a better solution?
0
 
LessIsMoreAuthor Commented:
sure, I thought this is what we are doing, script?
0
 
OriNetworksCommented:
What you requested was a web page. What i an suggesting is either a .net application or some other scripting method where the person loggin onto the computer knows where to get the script and then runs it. Would this be useful in your scenario?
0
 
OriNetworksCommented:
As an example if you had a .net console application that runs everytime a user logs in you could get the local computer name by
Dim computername as string = My.Computer.Name & "." & System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName

Open in new window

0
 
LessIsMoreAuthor Commented:
Can I create this .net console app? It's over my head.
0
 
OriNetworksCommented:
a .net console app is just a different project type in visual studio. Its still .net but it is a program that you run on each computer, not from a website.

Your official answer for this question is no, you cannot reliably collect a fqdn or even hostname of a client computer from a webpage using .net or javascript.
0

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now