Solved

NSLookup in ASP

Posted on 2012-04-05
7
591 Views
Last Modified: 2012-06-21
What is the easiest way to get a client host name in an ASP page?

comp_name=Request.ServerVariables("REMOTE_HOST")

Open in new window


This will give me my client IP address but I need to get the host computer name not address.
Is there and easy lookup tool or another syntax I can use?

Thanks
0
Comment
Question by:piemckay
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37811851
<%
  Set PCName = Server.CreateObject("WScript.Network")
  Response.Write PCName.ComputerName
%>
0
 

Author Comment

by:piemckay
ID: 37811901
This returns the server name not the client name.

Thanks though! Any other ideas?
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37811950
What do you mean by client name?

It returns the name of the computer you run it agains, server or no server.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:piemckay
ID: 37811982
The computer I am accessing the asp page through is the client. I want it to set comp_name to the name of my computer. For example my computer is called "API-GRP-WRK-445", the asp page is hosted on our IIS server "API-SVR-IIS-00".

When i use your code it will return the comp_name as "API-SVR-IIS-00" not "API-GRP-WRK-445".

Output
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37812135
You may have to ping the ip address yourself to get the computer name using the following command:

ping -a ipaddress
0
 

Accepted Solution

by:
piemckay earned 0 total points
ID: 37812253
Thanks for pointing me in the right direction. I used this

Dim comp_name
Dim oShell, oExec, sCommand, sOutput
comp_name= Request.ServerVariables("REMOTE_HOST")
sCommand = "%comspec% /c @echo off & for /f ""tokens=2"" %q in ('ping -n 1 -a " & sIP & "^|find /i ""pinging""') do echo %q"
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec(sCommand)
sOutput = oExec.StdOut.ReadAll
Set oExec = Nothing
Set oShell = Nothing

comp_name = sOutput 

Open in new window


Works perfect! Pity there is no simplie way of doing it.
0
 

Author Closing Comment

by:piemckay
ID: 37826766
This worked perfectly, it essentially is the only way to resolve a client IP address to a host name by pinging it and getting the results of that ping which includes the host name.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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