ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been messing with curl recently and am wanting to get results from mxtoolbox.com for blacklisted IP's as part of a bash script.
However I cannot get it to work, I have tried several ways but each fail.
I have recently found out about firebug for firefox using firecurl I am able to get what looks like a good curl command however it fails, If someone has the time to show me the error of my ways I would be grateful.
From firecurl I get two results each fails to return the same page as firefox does.
If I understand the situation correctly, if you were requesting the information
using a browser, you'd normally visit a page, type in values to a form,
then submit the page.
If the values are submitted via POST, I'd usually expect to see the form data
"encoded".
In the second curl command example you posted, one of the headers indicates
that encoded form data will be provided. AFAIK, with curl, form data can
be provided with options such as -F or --form or --form-string.
It appears the --form-string option was used, but it's empty. Curl seems
to be complaining because the string supplied is empty.
I don't know which page on the site you are trying to emulate, but when I visit
a number of the pages on the site, they have actual forms with actual input
fields, to look up information. I would expect that the site would want actual
form data to be submitted.
Maybe there's something I'm missing, or perhaps if I looked at the very latest
RFC's I'd discover that parameters are somehow acceptable on a URL for a POST,
but it's not something I'm used to seeing. I'm currently building a web site,
using POST virtually exclusively, and you won't see any parameters on the URL's
submitted by the browser. Yet, in your second example there's a parameter on a
URL, but curl is seemingly being instructed, via the -X parameter, to use POST.
I use firebug for somethings; I'm not quite sure how you are trying to use it,
or if it may somehow be confusing the situation.
Usually if I'm trying to automate the retrieval of data from a web site,
I'll use something a bit simpler than firebug, such as httpfox, to largely
just watch the HTTP going back and forth, as I'm using the web site manually
to successfully get data. I'll use some of the options on curl or wget
to handle cookies.
I'll also analyze the pages involved. There can be hidden fields, and
I believe when I glanced at some of the pages from the web site involved
in your situation, I saw a variety of hidden fields.
There can also be javascript data, or values modified by javascript.
All those things may need to be sent to the site in one way or another,
for a request to be honored. With javascript, the values it sets may
depend on the data entered into a form. So it may not be possible to
simulate the page in a static/fixed manner. The simulation may need
to be dynamic/changeable.
I don't know how the curl commands are being generated in your situation,
but one way or another, I would expect that you'd have to get the form
data correctly specified to curl.
Thanks kakaka for your reply, when I examined the site more closely I saw it uses javascript for the form http://mxtoolbox.com/blacklists.aspx Usually I enter a Server IP and use the submit button which after a few seconds returns the results as a list of blacklist sites and verifies if the IP is on any of them.
Since it is using javascript I assume this is going to be more difficult than I expected, as for the firecurl data, I was more hoping it was mostly good and just needed a tweak to fix the error message, I see now that it probably incomplete and to get the information I require from a script will take a lot more work and understanding of javascript, cookies and curl.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.