Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read IP addr of your PC?

Status
Not open for further replies.

Shaz444

Technical User
Oct 20, 2003
15
CA
I want to read the IP address of my PC & post it to a ISP web page for viewing later on!
I want to view the IP address of my computer at regular intervals of 3 hours? Can asp manage cmd prompts?
Is there a way to do it in asp or do I have to program in C++ / VB ?

 
Just some thoughts here.

ASP can return the REMOTE_ADDR (IP) of the requesting host - Request.ServerVariables("remote_addr"). But, as ASP infers, the server must run the procedure. So, the returned IP is what the server sees.

You can generally get your IP using ASP on an external website - if you don't use a proxy. A proxy assigns an IP unrelated to your machine IP. So, even if you have a fixed IP, the IP returned by REMOTE_ADDR will be the proxy assigned IP. Unfortunately, you do not always know if you are being proxied.

If the ASP is run on a local website (on your machine), you can get the actual IP before any proxying.

So, it kind of depends on what IP you are interested in. Actual or proxy assigned.

How you post this returned IP to a website for viewing later is another matter. Your best bet is to store the information in a database and read the database with ASP on the website. If you are running the ASP REMOTE_ADDR call on your local machine (to get the actual IP), then you could FTP the database to an external website using ASP although it may require a 3rd party component.
 
i think he's looking more to keep track of his own ip ( dialup ) unfortunately localhost will always show up as 127.0.0.1 and unless you're mapping to your assigned ipaddress, you will only fetch 127.0.0.1 from remote_addr

try typing ipconfig @ cmd prompt, you can make a asp page with execute permissions in it, output ipconfig to a file, the parse the file contents into the page you're wanting to track yourself with

you can even use windows task scheduler to run ipconfig to file on a schedule.

ipconfig>tempfile.txt

tempfile.txt will contain the output of ipconfig
 
That's interesting, DreXor. Before I responded, I tried it on my machine and it returned the DHCP assigned IP from my router - the same as is returned by ipconfig. I assumed it would do the same from a dialup connection. Have you tried it?
 
kind of depends you can do it by machine name, machine name will "usually" return assigned ip, sometimes it just acts like localhost, i've had issues in the past with trying to do development on dialup in the past ( whe good old days, they didn't have cars back then *LOL* ) and trying to do a form of dynamic DNS to my dialup connection etc etc..

there's a few ways of getting around this, one of which i mentioned it's the "crude yet effective" method, and is windows friendly ( cept win95 ) because ipconfig is a standard config tool passed with pretty much every version i know of.

the "clean and spiffy" way to do it would be to create a server side component that references some registry or config file entries to denote where you want your ip addie broadcast to, using http to pass it to a server/page for reassignment.

although the original question was a little vague in the matter, i took a leap of faith on what he was asking to try and do, otherwise i would have just denoted config the page on the server to read remote_addr, but even then without something to schedule it , you'd have to hit the page everytime you logged in to register your ip
 
How about creating two pages on the remote server?
Code:
[b]Page1[/b]
<%
'obviously this will only work if you aren't being proxied
Response.Write Request.ServerVariable("REMOTE_ADDR")
%>

[b]Page2[/b]
<%
Dim fso, fil, path
path = Server.MapPath("ip.txt")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If Request.QueryString("ip") <> "" Then
   Set fil = fso.OpenTextFile(path),2,True)
   fil.WriteLine Request.QueryString("ip")
   fil.Close
   Set fil = Nothing
Else
   If fso.FileExists(path) Then
      Set fil = fso.OpenTextFile(path,1,False)
      Response.Write fil.ReadAll
      fil.Close
      Set fil = Nothing
   Else
      Response.Write "No IP Address recorded yet."
   End If
End If
%>

Then you would justneed some sort of scheduled task running locally to go out and hit the pages in order. You could put together a small vbs script to use the XMLHTTP object to do this:
Code:
[b]MyScript.vbs[/b]
Dim objXMLHTTP
Dim URL
URL = "[URL unfurl="true"]http://www.where.com/"[/URL]
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", URL & "page1.asp", False
objXMLHTTP.Send

Dim ip_addy
ip_addy = objXMLHTTP.ResponseText

Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", URL & "page2.asp?ip=" & ip_addy, False
objXMLHTTP.Send

Set objXMLHTTP = Nothing

Save the vbs script locally and set it up as a scheduled task. It goes to the first page and gets your address. It submits that address to the second page. Anytime you want to see your address you just go to the second page (without an ip address in the querystring) and it will display the last one it wrote to the text file.

Hopefully tat covers what you were looking for, there may be some syuntax errors in there, i wrote this on the fly.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top