Page 1 of 1
How do I do this? Data entry into a field
Posted: Tue Sep 25, 2007 7:07 pm
by legend986
I was curious if automated tasks are possible with php. Suppose that I have this website:
Code: Select all
http://relcom.net/INFO/NOC-IP/lg/lg0.html
And a set of 50 IP addresses in a file. Is there a way I could actually put these IP addresses one by one into the
Address field in the website and then when the results appear in the frame to the right, paste the results into a database or a file?
Posted: Tue Sep 25, 2007 7:40 pm
by feyd
Why wouldn't it be possible?
Posted: Tue Sep 25, 2007 7:41 pm
by legend986
Ok... I'll re-frame the question... How would I do it? Sorry about that..

Posted: Tue Sep 25, 2007 8:06 pm
by EricS
I suggest you look into the curl extension. It allows you to post data to a form and retrieve the response. You can than, as you say, paste the result into a database or file.
Posted: Wed Sep 26, 2007 4:50 pm
by legend986
Thank you so much. I've started using curl and I think that is most appropriate to get the job done. I was curious about one thing. I'm still reading the curl guide so it would take time to implement and test this. But, if the script (cgi in this case) says it is not possible to directly post the values, would I still be able to use curl? I mean, the website uses frames. I post data through frame 1 and the output is generated at frame 2. Will I be able to use curl for this purpose?
Posted: Wed Sep 26, 2007 5:44 pm
by EricS
Okay. First think about what's really happening with this site.
http://relcom.net/INFO/NOC-IP/lg/lg0.html is just an html file which is defining a frameset. Its simply saying load "lg1.html" onto the left side of the browser window and load "lg2.html" onto the right side of the browser window. So this file is just telling the browser how to split the current windows into two sections and what to load into those sections. You can safely ignore this as far as your programming is concerned.
http://relcom.net/INFO/NOC-IP/lg/lg1.html is a form you fill out. It the submits to
http://relcom.net/INFO/NOC-IP/lg/lg1.cgi and it tells the browser that the response from lg1.cgi should be loaded into the right side of the browser. So in all reality, your script is only going to be dealing with
http://relcom.net/INFO/NOC-IP/lg/lg1.cgi
Now by looking at the source code for
http://relcom.net/INFO/NOC-IP/lg/lg1.html, you can dissect the form and extract it's form variables. Once you've dissected that form you no longer need lg1.html either.
So now you've eliminated all the junk in the way and you now know you only need to deal with
http://relcom.net/INFO/NOC-IP/lg/lg1.cgi.
CURL can POST form variables to the cgi script. The cgi script can't stop you from doing this. It can however try and determine if that's what your doing and give you an error if it suspects your doing it. Fortunately CURL also has the ability to control all headers and meta data that cgi script may be looking at. So it might look at the http-refer header to see if you are direct submitting or actually using their form. They can look at the agent header to see if you actually using a browser. etc etc etc.
Now your only job (as I've broken down all the research for you already) is determine what that cgi script is looking for in the headers to help it determine if you are posting directly (via CURL) or through their own web page.
And I went ahead and figured that out for you too. Below is a curl command that works perfectly (I've tested it).
Code: Select all
curl -e "http://relcom.net/INFO/NOC-IP/lg/lg1.html" -F "ROUTER=M9-16&query=trace&addr=64.233.167.99&submit=Submit" http://relcom.net/INFO/NOC-IP/lg/lg1.cgi
BTW this all a one line command, do not put a line break anywhere in it.
Simply change the value after query= if you want a different action than trace and change the IP address after addr= with your own ip addresses (one at a time).
Posted: Sat Sep 29, 2007 5:56 pm
by legend986
Thank you so much and sorry for the delay in replying... You sure have lots of patience to type all that
