Solved

Need to gather FQDN from users

Posted on 2015-02-20
17
33 Views
Last Modified: 2015-06-02
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
Comment
Question by:LessIsMore
  • 9
  • 7
17 Comments
 
LVL 17

Assisted Solution

by:OriNetworks
OriNetworks earned 500 total points
ID: 40622313
Do you mean fqdn of their computer? You could use UserHostName
https://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostname.aspx
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40622316
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
 

Author Comment

by:LessIsMore
ID: 40623099
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 17

Expert Comment

by:OriNetworks
ID: 40625746
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
 

Author Comment

by:LessIsMore
ID: 40625942
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
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40626475
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
 

Author Comment

by:LessIsMore
ID: 40630891
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
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40631169
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
 

Author Comment

by:LessIsMore
ID: 40631408
I get BC30109: 'String' is a class type and cannot be used as an expression.
on line 7
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40632124
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
 

Author Comment

by:LessIsMore
ID: 40633255
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
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40633263
If FQDN is absolutely required would deploying some kind of small application or script be a better solution?
0
 

Author Comment

by:LessIsMore
ID: 40633686
sure, I thought this is what we are doing, script?
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40634207
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
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40634221
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
 

Author Comment

by:LessIsMore
ID: 40634238
Can I create this .net console app? It's over my head.
0
 
LVL 17

Accepted Solution

by:
OriNetworks earned 500 total points
ID: 40634513
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
I've written instructions for one router type, but this principle may be useful for others of the same brand and even other brands of router. Problem: I had an issue especially with mobile devices that refused to use DNS information supplied via…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question