?
Solved

Need to gather FQDN from users

Posted on 2015-02-20
17
Medium Priority
?
40 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 17

Assisted Solution

by:OriNetworks
OriNetworks earned 2000 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
Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

800 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