开发者

Simple telnet example in LIBCURL - C++

I need to fing simple TELNET example in LIBCURL (curl.haxx.se/libcurl) (C++) I searc开发者_运维问答hed over this site, but I don't found any simple example. I need only to connect to TELNET, authenticate, and send message.

Thanks


All you can do in libcurl is send data and recieve data. There is no way to wait for response or send data based on response. The whole point of libcurl is to handle waiting for data and responses for HTTP or FTP.

That being said, you may be able to do something with CURLOPT_READFUNCTION and CURL_READFUNC_PAUSE. Return PAUSE from READFUNCTION, then call curl_easy_pause(CURLPAUSE_CONT) when you see "login:" in your READFUNCTION. Be prepared to return your user name from READFUNCTION when it gets called.

I've never done this, so I can't vouch for how it works. But from API description, this seems to be the way to go...


NOTE: The telnet protocol does not specify any way to login with a specified user and password so curl can't do that automatically. To do that, you need to track when the login prompt is received and send the username and password accordingly.

You can look it here: http://www.cs.sunysb.edu/documentation/curl/index.html

Maybe you should make it manually like:

system("curl telnet://192.168.2.1");

Later it will ask your username and password.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜