Simple telnet example in LIBCURL - C++

删除回忆录丶 提交于 2019-12-24 01:24:58

问题


I need to fing simple TELNET example in LIBCURL (curl.haxx.se/libcurl) (C++) I searched over this site, but I don't found any simple example. I need only to connect to TELNET, authenticate, and send message.

Thanks


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/1687369/simple-telnet-example-in-libcurl-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!