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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using form results from another site 1

Status
Not open for further replies.

orlandoj

Programmer
Feb 10, 2003
27
US
Hi, I built a webcounter for my site using ASP. I am interested in using an IP address locator, such as the one at . Is there a way for me to submit the user's IP address to this site and get the results back on my site?

Thanks,
-Jamie
 
not unless they expose an API or webservice...that data is posted to and results displayed by THEIR page.



=========================================================
while (!succeed) try();
-jeff
 
You can use ServerXMLHTTP to simlate http GET

try this:

<br>
<form action=&quot;httpGet.asp&quot; method=&quot;post&quot;>
URL:<input type=&quot;text&quot; name=&quot;url&quot; size=&quot;50&quot; value=&quot;<% =Request.Form(&quot;url&quot;)%>&quot;>
<br>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Get It!&quot;>
</form>
<br>
<hr>
<%
if(Request.Form(&quot;url&quot;) <> &quot;&quot;) then
Response.Buffer = True
Dim objXMLHTTP, xml

' Create an xmlhttp object:
Set xml = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject(&quot;MSXML2.ServerXMLHTTP&quot;)

' Opens the connection to the remote server.
xml.Open &quot;GET&quot;, Request.Form(&quot;url&quot;), False

' Actually Sends the request and returns the data:
xml.Send

'Display the HTML both as HTML and as text
Response.Write &quot;<h1>The HTML text</h1><xmp>&quot;
Response.Write xml.responseText
Response.Write &quot;</xmp><p><hr><p><h1>The HTML Output</h1>&quot;

Response.Write xml.responseText

Set xml = Nothing

End If
%>
 
I think the problem is that orlandoj wants to get the results of the post back, not simulate the post to the page.

=========================================================
while (!succeed) try();
-jeff
 
It would be nice to be able to get the results of the post back, just so I know how to do it, but in this particular instance, they've made all the form fields have the same name (I guess to try to prevent people to do what I'm doing). Nevertheless, if I have the 'xml.responseText', I can parse that and pull the data out that I need. If I get this figured out, I'll post my code to this thread. Thanks everybody. You've been most helpful!
 
orlandoj,

in that case, you could simply copy the html source of their form to your site:

locateIP.html
Code:
<html>
<head>
<title>Locate IP</title>
</head>
<body>
<div align=&quot;left&quot;>
<form method=&quot;POST&quot; action=&quot;[URL unfurl="true"]http://www.geobytes.com/IpLocator.htm?GetLocation&quot;[/URL] name=&quot;iplocator&quot;>
  <table border=&quot;0&quot; cellpadding=&quot;3&quot;>
    <tr>
      <td>
  <input type=&quot;hidden&quot; name=&quot;cid&quot; value=&quot;<%cid%>&quot;><input type=&quot;hidden&quot; name=&quot;c&quot; value=&quot;<%c%>&quot;><input type=&quot;hidden&quot; name=&quot;Template&quot; value=&quot;iplocator.htm&quot;>
  <h3>IP Address to locate:<input type=&quot;text&quot; name=&quot;ipaddress&quot; size=&quot;15&quot; value=&quot;207.71.204.122&quot;> <input type=&quot;submit&quot; value=&quot;Submit&quot;>
  </h3>

</td>
      <td> <font style=&quot;background-color: #FFFF00&quot;>   <b></b>
  </font></td>
    </tr>
  </table>
  </form>
</div>
</body>
</html>

=========================================================
while (!succeed) try();
-jeff
 
Jeff,

I understand that I can include their form code on my site. I'm actually interested in being able to get the RESULTS of the form.

If it helps at all I'll explain what I'm trying to do.

I programmed a web-counter storing each user's IP address in a database. I want to be able to have my counter automatically look up the user's Country, Region and City and store it in my database all automatically when someone hits my site.

If there's an easier way of retrieving the form results rather than having to parse that HTML file, it would be greatly helpful!

Thanks so much,
-Jamie
 
i see...how about using a regular expression to parse it for you:

Code:
<html>
<head>
<title></title>
	<script type=&quot;text/javascript&quot;>
		sHTML = '  <table>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Country Code <input name=&quot;ro-no_bots_pls&quot; value=&quot;US&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Country <input name=&quot;ro-no_bots_pls&quot; value=&quot;United States&quot; size=&quot;20&quot;> </td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Region Code <input name=&quot;ro-no_bots_pls&quot; value=&quot;USFL&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Region <input name=&quot;ro-no_bots_pls&quot; value=&quot;Florida&quot; size=&quot;20&quot;> </td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>City Code <input name=&quot;ro-no_bots_pls&quot; value=&quot;USFLNPRI&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>City <input name=&quot;ro-no_bots_pls&quot; value=&quot;New Port Richey&quot; size=&quot;20&quot;> </td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Latitude <input name=&quot;ro-no_bots_pls&quot; value=&quot;28.2512&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Certainty <input name=&quot;ro-no_bots_pls&quot; value=&quot;82&quot; size=&quot;20&quot;> </td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>TimeZone <input name=&quot;ro-no_bots_pls&quot; value=&quot;-05:00&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Longitude <input name=&quot;ro-no_bots_pls&quot; value=&quot;-82.6709&quot; size=&quot;20&quot;> </td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Capital City <input name=&quot;ro-no_bots_pls&quot; value=&quot;Washington, DC &quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Is proxy <input name=&quot;ro-no_bots_pls&quot; value=&quot;false&quot; size=&quot;20&quot;></td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Nationality Singular <input name=&quot;ro-no_bots_pls&quot; value=&quot;American&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>CIA Map Reference <input name=&quot;ro-no_bots_pls&quot; value=&quot;North America &quot; size=&quot;20&quot;></td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Currency <input name=&quot;ro-no_bots_pls&quot; value=&quot;US Dollar &quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Nationality Plural <input name=&quot;ro-no_bots_pls&quot; value=&quot;Americans&quot; size=&quot;20&quot;></td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;>Population<input name=&quot;ro-no_bots_pls&quot; value=&quot;278058881&quot; size=&quot;20&quot;> </td>' +
		'    <td align=&quot;right&quot;>Currency Code <input name=&quot;ro-no_bots_pls&quot; value=&quot;USD&quot; size=&quot;20&quot;></td>' +
		'  </tr>' +
		'  <tr>' +
		'    <td align=&quot;right&quot;><b><a href=&quot;[URL unfurl="true"]http://www.ripe.net/perl/whois?query=64.57.10&.submit=Submit+Query&quot;[/URL] target=&quot;_blank&quot;>RIPE</a>  <br>' +
		'      </b>Search WHOIS data at: <b><a href=&quot;[URL unfurl="true"]http://www.arin.net/cgi-bin/whois.pl?queryinput=64.57.10&quot;[/URL] target=&quot;_blank&quot;>ARIN</a>  </b><a href=&quot;[URL unfurl="true"]http://www.apnic.net/apnic-bin/whois2.pl?results=all&search=64.57.10&whois=Go%21&quot;[/URL] target=&quot;_blank&quot;><b><br>' +
		'      APNIC</b></a> </td>' +
		'    <td align=&quot;right&quot;>Flag <a href=&quot;FreeServices.htm&quot;><img border=&quot;0&quot; src=&quot;[URL unfurl="true"]http://www.geobytes.com/Flags/US-flag.jpg&quot;[/URL] width=&quot;81&quot; height=&quot;54&quot;></a></td>' +
		'  </tr>' +
		'</table>';

		function getVals() {
			var regex = /<input name=&quot;ro-no_bots_pls&quot; value=&quot;[^\&quot;]*&quot; size=&quot;20&quot;>/gi;
			var aMatches = sHTML.match(regex);
			var vals = document.getElementById(&quot;vals&quot;);
			
			for (var x = 0; x < aMatches.length; x++) {
				var val = aMatches[x].match(/value=&quot;([^\&quot;]*)&quot;/)[1];
				vals.innerHTML += &quot;[&quot; + x + &quot;] = &quot; + val + &quot;<br/>&quot;;
			}
		}
		
	</script>
</head>
<body onload=&quot;getVals();&quot;>
	<div id=&quot;vals&quot;></div>
</body>
</html>


================================================================================================================================================================================================================================================================================================
=========================================================
while (!succeed) try();
-jeff
 
as this may be more relevant, here's an example in asp:

<%
sHTML = xml.responseText

set oRE = new regexp
oRE.pattern = &quot;<input name=&quot;&quot;ro-no_bots_pls&quot;&quot; value=&quot;&quot;[^\&quot;&quot;]*&quot;&quot; size=&quot;&quot;20&quot;&quot;>&quot;
oRE.global = true
oRE.ignorecase = true

set oMatches = oRE.execute(sHTML)

oRE.pattern = &quot;value=&quot;&quot;([^\&quot;&quot;]*)&quot;&quot;&quot;

for each oMatch in oMatches
tmp = oMatch.value
set val = oRE.execute(tmp)
response.write(mid(val(0), 8, len(val(0)) - 8) & &quot;<br/>&quot;)
next
%> =========================================================
while (!succeed) try();
-jeff
 
Ahhh I almost forgot. As promised, here's the code for my new and improved webcounter. I have a feeling some of the code I did in here was inefficient or unnceccessary, but I'm new to ASP, and this code works. Thanks again everybody!
==================

<%
Response.Buffer = True

Dim path
Dim conn
Dim ipaddr
Dim fromPage
Dim xml
Dim loopcount
Dim country
Dim region
Dim city
Dim query

loopcount = 0

path = Server.MapPath(&quot;/database/counter.mdb&quot;)
Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & path & &quot;;&quot;

Set ipaddr = Request.ServerVariables(&quot;REMOTE_ADDR&quot;)
Set fromPage = Request.ServerVariables(&quot;HTTP_REFERER&quot;)

Set xml = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)

xml.Open &quot;GET&quot;, &quot; & ipaddr, False

xml.Send
sHTML = xml.responseText
set oRE = new regexp
oRE.pattern = &quot;<input name=&quot;&quot;ro-no_bots_pls&quot;&quot; value=&quot;&quot;[^\&quot;&quot;]*&quot;&quot; size=&quot;&quot;20&quot;&quot;>&quot;
oRE.global = true
oRE.ignorecase = true
set oMatches = oRE.execute(sHTML)
oRE.pattern = &quot;value=&quot;&quot;([^\&quot;&quot;]*)&quot;&quot;&quot;

for each oMatch in oMatches
loopcount = loopcount + 1
tmp = oMatch.value
set val = oRE.execute(tmp)
if loopcount = 2 then
country = mid(val(0), 8, len(val(0)) - 8)
else
if loopcount = 4 then
region = mid(val(0), 8, len(val(0)) - 8)
else
if loopcount = 6 then
city = mid(val(0), 8, len(val(0)) - 8)
end if
end if
end if
next


Set query = conn.Execute(&quot;INSERT INTO counter_table (hitdate, hittime, ip, dns, link, country, region, city) VALUES (Date(), Time(), '&quot; & ipaddr & &quot;', '', '&quot; & fromPage & &quot;', '&quot; & country & &quot;', '&quot; & region & &quot;', '&quot; & city & &quot;')&quot;)

conn.Close
Set conn = Nothing
Set xml = Nothing
%>
 
looks good! i like to use &quot;select case&quot; for bigger if...then constructs:

for each oMatch in oMatches
loopcount = loopcount + 1
tmp = oMatch.value
set val = oRE.execute(tmp)

select case loopcount
case 2
country = mid(val(0), 8, len(val(0)) - 8)
case 4
region = mid(val(0), 8, len(val(0)) - 8)
case 6
city = mid(val(0), 8, len(val(0)) - 8)
end select
next =========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top