How to translate incoming Telnet data from external device into VB6 - vb6

I made a connection to a external device.
The problem is that the feedback I get right after establishing connection is kind of as ASCII code:
ÿý↑
After checking theese sites:
Telnet
ASCII
Charsets
US-ASCII
Convert
I found out that:
ÿ is 255 which stands for IAC (Interpret as Command) and
ý is 253 which stands for DO and
↑ is 24 which stands for Cancel.
To send back commands to the terminal I do this:
winsck.SendData Chr(255) 'IAC
winsck.SendData Chr(252) 'WONT
winsck.SendData Chr(24) 'CANCEL
To translate an ASCII code to a char I made the following code:
lblChar = Asc(txtASCII)
To translate a char to an ASCII code I made the following code:
lblASCII = Chr(txtChar)
I want data from the terminal and modify them, but first I have to get through this ASCII coding.
How it normally works in cmd.exe:
I write telnet followed by the ipaddress of destination:
telnet (ipaddress of the terminal)
then cmd asks me for the password. After that I would be ready to write commands. Normally I write like
lm -h
then it would send me a lot of data. I want to do the same with my VB6 program.
After sending the terminal "IAC WON'T CANCEL" I got back:
ÿþ↑ÿû ÿûᶫÿý
As I have trying to translate it and I came to this result:
IAC - DON'T - CANCEL - IAC - WILL (space) IAC - WILL - END OF TEXT - IAC - DO
and after sending the terminal "IAC WILL CANCEL"
I got back: ÿú↑ ÿð= "IAC - Subnegotiation of the indicated option follows - CANCEL (space) IAC - End of subnegotiation parameters"
Seriously what does it mean - what should I answer back?
Thanks in advance

It appears that your device acts as a Telnet server and you need to implement a client in VB6.
Have you looked at Telnet Client UserControl yet?

Since those looks like Telnet commands and you mention that you can get out data if you connect via Telnet I assume you'd have to write a Telnet client. I'd suggest beginning with doing a search for telnet RFC if you go down this route and possibly telnet client vb6 too.
However, another alternative might be to automate a telnet client like Putty, this question might be helpful with that: How to run a command file in PuTTY using automatic login in a command prompt?

Related

AT+CMGS - Can not excape text input mode

I am using PuTTY to connect to an industrial cellular router , to send SMS via AT-Commands.
In PuTTY, I select Telnet and connect to the IP-Address of the router on port 23:
Router loging: root
Password: ****
# gsmat ATE1 // turn echo on
OK
# gsmat AT+CMGF=1 // switch to text mode (0 = PDU mode)
OK
# gsmat AT+CMGS=\"0664XXXXXXXX" // "tel. number"
> Test message [ENTER] // new line (expected)
> [Ctrl-Z] // nothing happens, also with Alt+0026, etc.
> [Ctrl-D]
> -sh: syntax error: unterminated quoted string
#
I normaly the SMS should send on Ctrl+Z (according to documentation, forums, etc.), but nothing happens.
So i tried the following:
ASCII code: [Alt+0026] for substitute (Ctrl+Z), nothing happens, also with Hex: 0x1A
Copy and past [SUB] from Notepad++, nothing happens (copy and paste normal text into PuTTY works fine)
[Ctrl-Y] as suggested in some forum, maybe because german keyboard layout (also nothing happens)
[Ctrl-D], syntax error, input escapes, but of course sending failes
I also tried different tools like Hyperterminal, SSH from CMD, Hercules tool, ...
Has anyone an other idea how to escape this text input mode in this situation?
My goal is to send an SMS autmatically via an C# service and there I just add (char)26 to my input and it works.
inputString = message.Length > 160 ? message.Substring(0, 160) : message;
inputString += (char)26;
connector.Write(inputString);
Any suggestions are appreciated
Screenshot: PuTTY connection settings
Screenshot: PuTTY terminal input
What I do is send SMS via PDU mode. It's a little more effort, but much better for automatic SMS sending.
According to several Internet sources, such as this one CTRL+Z is a shortcut that makes you
Put whatever you are running into a suspended background process. Type fg to restore it
which seems exactly what you are experiencing: CTRL+Z character is actually never sent, and that's the reason why the modem never sends its response.
As far as I know, sending ASCII 0x1A (decimal 26) should be correctly recognized by PuTTY. But since you already tried it there must be some other issue, and a different attempt has to be done.
Fortunately, process suspend feature can be disabled: as shown in PuTTY user guide that functionality is called Keyboard sends Telnet special commands.
In order to disable it:
Open PuTTy Configuration
Category Connection -> Telnet
Unflag Keyboard sends Telnet special commands option
It seems the problem is associated with the SMSC number.
AT+CSCA="+SMSC number"\r\n solved the problem

Telnet client negotiation not working properly

I am designing telnet client, which negotiates telnet options. I send desired commands to server, and process server's requests and responses. But at least color terminal identification has no effect: remote Linux server continues sending data without color ESC sequences until I explicitly tell it (through its dialog) that my client supports color.
However windows telnet and hyperterminal is being fed by the color information just after telnet negotiation, and I am looking for what they do I do not. Here's what I see:
telnet
hyperterminal
I see that server performs 255 cursor right and 255 cursor down, and then requests cursor position report, and client reports ESC [ 24;80R (which is correct), and just after this server starts color communication.
Here's what my client does
It does not have ESC [ R command supported, and does not respond for reporting cursor position. I must say that server seem to wait for several seconds for something exactly at the time when it performs these right/down cursor movements.
If it the issue why I do not have color data from the server, or there's something else you can see in the operation of my client?
Interesting that I have a video of another client which also is not expected to support ESC R command, but I see server starts sending ESC color codes after negotiation. So I have a feeling that it may not be this cursor report command issue.
Answer: after implementation of the "report position" response of the client to the server, server sends ESC color sequences now. Thus this functionality was vital for the general client-server handshaking.

Sending MMI codes from bash script

I am trying to make a little bash script that will activate call forwarding to some number on some condition using mobile broadband dongle connected to the usb port.
I can easily send sms messages, call USSD codes using either mmcli (ubuntu) or gammu, but I cannot run MMI codes. These codes have very similar syntax to USSD but are not the same.
Can I send MMI codes using any command line tool? If yes - how?
You can manage call forwarding directly by Gammu, see http://wammu.eu/docs/manual/gammu/#cmdoption-gammu-arg-divert

Transferring files using Telnet

Is it possible to transfer files between two machines using Telnet protocol. From wikipedia,I understand that FTP & Telnet are similar. But on logging in using Telnet its very similar to logging into guest machine.
Please advise.
You cannot transfer a raw binary file over telnet because there are some codes that are reserved and will be escaped before transmission. Your local telnet terminal would also interpret other codes as cursor control sequences and go wild.
So no cat stuff.zip and extracting it locally from the log file or screen cut/paste.
However, you could encode a file into something safe using uuencode or base64, capture that on the local side, and decode it using the appropriate tool to get the original binary back.
But in short, just use FTP in "binary" plus "passive" mode. That's safest and what it's designed for.
That said, you should be using SSH instead of Telnet and then you can use SCP to transfer files.

Run and show Batch file commands on telnet

Not only for the host running. Bat, but to run and display the output text to the client (Telnet)
This is possible?
I have tried and tested everything and could not.
If it is not really possible, which file should I edit to edit the text output from telnet and what language is it?
from what little I understood, you just want to send the output of a file to another computer using telnet. if so try file | telnet. or... cough ...
you could use netcat, if it was one time and you were carful it shouldn't pose a huge threat.
nc -lp12123 on the server, and connect with nc server 12123 -efile.bat on the client.
if neither of these suit then please post more info.

Resources