Solved

Need to gather FQDN from users

Posted on 2015-02-20
17
31 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 39

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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (https://kb.isc.org/article/AA-01272), affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now