Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Net::Telnet to IO::Socket::INET

by sans-clue (Beadle)
on Mar 08, 2013 at 00:46 UTC ( #1022321=perlquestion: print w/ replies, xml ) Need Help??
sans-clue has asked for the wisdom of the Perl Monks concerning the following question:

I had much success using Net::Telnet to connect to a socket on a mainframe that delivered messages. Now that the mainframe had an upgrade and it seems to be sending EBCDIC rather than ascii. The mainframe people can't back out the change or figure out how to make the data be ascii again. I tried to adjust the Net::Telnet script to use a call to ebcdic2asciii found in Convert::EBCDIC. Of course nothing comes out or I wouldn't be writing. If I just telnet to the socket, I do see characters, weird ones of course. I assume I might be better off using IO:Socket::INET, but I am not sure how to make sure I stay connected unless the remote socket dies and how to tell I have 'enough' data that I can use ebcdic2ascii on. I simply want to print the incoming data to the screen. Here is telnet output, probably not useful, just showing there IS something.
Escape character is '^]'. cla;ccc}Q&P !cmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€cc +mcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€c^] telnet> quit
Here is my basic attempt, which connects but doesn't print anything.
#!/usr/bin/perl use IO::Socket::INET; use Convert::EBCDIC; my ($socket,$client_socket); $socket = new IO::Socket::INET ( PeerHost => '1.2.3.4', PeerPort => '6106', Proto => 'tcp', ) or die "ERROR in Socket Creation : $!\n"; print "TCP Connection Success.\n"; # read the socket data sent by server. $data = <$socket>; print "Received from Server : $data\n"; $data = ebcdic2ascii($data); print "Received from Server after : $data\n"; sleep (10); $socket->close();
Any ideas of what to try ? Thanks

Comment on Net::Telnet to IO::Socket::INET
Select or Download Code
Re: Net::Telnet to IO::Socket::INET
by andal (Friar) on Mar 08, 2013 at 10:38 UTC

    Try to capture the session using wireshark. It would also be good to know what was the output before. Then looking at the captured data one may try to figure out what is really sent by the host.

    Do you connect to a telnet daemon? In this case raw socket will be tricky to use, since you'd have to handle network terminal stuff.

Re: Net::Telnet to IO::Socket::INET
by BrowserUk (Pope) on Mar 08, 2013 at 11:05 UTC
    cla;ccc}Q&P !cmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€ccmcz«¦¢º€¡¦¢€c^]

    Are you sure that is EBCDIC? It looks more like some form of encrypted handshaking to me. Are you sure they haven't just replaces Telnet with some kind of SSH equivalent?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks, I assume that EBCDIC would look like rubbish in a terminal session, rather than what it really is. I will try wireshark too.
      It doesn't look like a SSH handshake either.

      The first think you get from a SSH server is a banner indicating the server software and version. I.e.:

      SSH-2.0-OpenSSH_6.1p1 Debian-3

        Hm. Maybe its utf-ebcdic then.

        It is weirdly repetitious though.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022321]
Approved by vinoth.ree
Front-paged by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-12-23 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls