# Connecting to a Telnet Server & Displaying the Contents

**URL:** <https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895>\
**Category:** General\
**Created:** [23 December 2020 00:01 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895 "2020-12-23T00:01:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 00:01 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/1 "2020-12-23T00:01:45Z")

</div>

I'm having some telnet connection issues and need some help.

There are telnet servers that you can connect to that display ham radio stations that are on the amateur radio air waves. It sends a string (usually login:) and you type your call sign to login. It then spits out text like this with the spots when they appear. It's all automatic. No user intervention in the telnet session. The spots are filled out by others through a website entry and then are replicated through these telnet servers called "the DX cluster".

Here is an example of the output from one of these telnet sessions. New spots populate at the bottom.

DX de W6RK: 3556.5 K8ZZ Gallatin/Saline, IL CW 1901Z  
DX de W6RK: 7056.5 K8ZZ Gallatin/Saline, IL CW 1906Z  
DX de W6RK: 10124.5 K8ZZ Gallatin/Saline, IL CW 1907Z  
DX de W6RK: 18091.5 K8ZZ Gallatin/Saline, IL CW 1912Z  
DX de W6RK: 3556.5 K8ZZ Hamilton/White, IL CW 1947Z  
DX de W6RK: 7056.5 K8ZZ Hamilton/White, IL CW 1950Z  
DX de W6RK: 10124.5 K8ZZ Hamilton/White, IL CW 1952Z  
DX de W6RK: 3556.5 K8ZZ Wabash, IL CW 2051Z  
DX de W6RK: 7056.5 K8ZZ Wabash, IL CW 2056Z  
DX de W6RK: 10124.5 K8ZZ Wabash, IL CW 2058Z  
DX de W6RK: 18091.5 K8ZZ Wabash, IL CW 2103Z  
DX de W6RK: 3556.5 K8ZZ Edwards, IL CW 2114Z  
DX de W6RK: 7056.5 K8ZZ Edwards, IL CW 2117Z  
DX de W6RK: 10124.5 K8ZZ Edwards, IL CW 2120Z  
DX de W6RK: 24913.5 K8ZZ Edwards, IL CW 2128Z  
DX de W6RK: 3556.5 K8ZZ Posey/Vanderburgh, IN CW 2211Z  
DX de W6RK: 7056.5 K8ZZ Posey/Vanderburgh, IN CW 2217Z  
DX de W6RK: 10124.5 K8ZZ Posey/Vanderburgh, IN CW 2220Z

I've loaded the telnet pallet, and have tried to connect, but I'm a little confused after the server sends me the "login:" I need to send it my call sign. Not even getting that far. Debug says "connection to the server timed out". I can telnet into it all day with no issues.

I'd like to read the above string into a JSON file so I can do some work, filter for specific states and modes and then spit it back out to a screen so we can view.

Thanks  
Kyle

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2020 02:42 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/2 "2020-12-23T02:42:54Z")

</div>

Hi. As telnet is just TCP, try putting a TCP request node set to port 22 & send your call sign (probably terminated with a cartridge return). See if it starts responding. Once you have it feeding back, we can split those strings into meaningful variables.

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 17:14 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/3 "2020-12-23T17:14:20Z")

</div>

Got it working.

Used the TCP request node and first did a inject node to get through the telnet connect banner. Then used another inject node to send my call sign with a slight delay.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/906465796fad05234fc25a7c24a3ff3ce76ed0e5.png)

Only thing I could not figure out was when I set msg.payload to aa0z\r\n in the inject node (as a string), it would send that actual sequence including the \r\n at the end.

When I used a function node in line and set msg.payload = 'aa0z\r\n'; return msg; it worked fine and sent my call sign with a carriage return.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2020 17:59 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/4 "2020-12-23T17:59:26Z")

</div>

Good stuff.

Have you managed to convert you strings into meaningful objects and properties?

> [@aa0z](#):
>
> Only thing I could not figure out was when I set msg.payload to aa0z\r\n in the inject node (as a string), it would send that actual sequence including the \r\n at the end.

The inject node sends the characters you enter.

The junction node is pure JavaScript so `\n` is escaped as expected.

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 18:39 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/5 "2020-12-23T18:39:44Z")

</div>

Thanks Steve. Makes sense. No coder here....so I'm slowing learning.

I haven't parsed the actual output yet, but I'm looking at the substr function as the length of the string is always 77 characters and the items I want to pull out are always at a fixed location.

I was heading down this path.

working with this string

DX de NX5M-#: 14030.0 FS5GL CW 20 dB 24 WPM CQ 1543Z

I was going to try --

let spot = msg.payload

let freq = spot.substr(18,7);  
let call = spot.substr(27,6);  
let comment = spot.substr(56,70);  
let time = spot.substr(71,4);  
return {payload:{freq:freq,call:call,comment:comment,time:time}};

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 18:45 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/6 "2020-12-23T18:45:11Z")

</div>

Updated code...

Input

DX de NC7J-#: 14028.0 K4JJW 14 dB 20 WPM MOQP 1630Z

Function node :

let spot = msg.payload  
let freq = spot.substr(17,7);  
let call = spot.substr(26,6);  
let comment = spot.substr(56,14);  
let time = spot.substr(70,4);  
return {payload:{freq:freq,call:call,comment:comment,time:time}};

Output ;

{"freq":"14028.0","call":"K4JJW ","comment":"MOQP ","time":"1630"}

On a roll here!!!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2020 21:45 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/7 "2020-12-23T21:45:35Z")

</div>

Good stuff - just wanted to check you were on the right path.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 December 2020 22:33 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/8 "2020-12-23T22:33:34Z")

</div>

If you had a blank array and pushed that object into it (and then same for next etc) then you could feed straight into a ui\_table node 😉

( in fact if you used unshift rather than push it would add new ones to the top of the table instead of the bottom)

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 22:43 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/9 "2020-12-23T22:43:24Z")

</div>

Thanks for the reply but totally over my head here with that comment.

I hit a snag on a variable length string that I need to format.....so I'm stuck on that at the moment.

Can you explain your first sentence again?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 December 2020 22:47 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/10 "2020-12-23T22:47:47Z")

</div>

Will do when I get back to a decent keyboard. ( unless someone else jumps in first)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2020 22:54 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/11 "2020-12-23T22:54:27Z")

</div>

I suspect what Dave as alluding to is instead of writing the data to a file (as was your initial intension)...

> [@aa0z](#):
>
> I'd like to read the above string into a JSON file so I can do some work, filter for specific states and modes and then spit it back out to a screen so we can view.

... I believe Dave was suggesting you could just push the objects that you create (these objects \>\> `{payload:{freq:freq,call:call,comment:comment,time:time}}` \<\<) into an array & therefore no need to write to file. Then you could send that array to a UI\_TABLE node (a dashboard node) for displaying a nicely formatted table of data

This is what ui\_table looks like...

 ![screenshot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/6182554f0c7ce3ee44b6e786f6bccf9d3c7806ce.png)

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [23 December 2020 23:06 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/12 "2020-12-23T23:06:33Z")

</div>

Ah, I see now.

Yes, I'd like to eventually see them in a table after comparing them to some other data, so this is good. I'll research how I can convert these objects into an array.

Thanks for the idea.

On my other issue, I have this data I'm getting out of my DX cluster. I'm reading data out of 4 telnet servers. 3 of them have the same format, so I can use the substr(x,y) function to format them into objects.

The 4th has a variable length with the county, 2 letter state, mode and the time.

DX de W6RK: 3556.5 K8ZZ Gallatin/Saline, IL CW 1901Z  
DX de W6RK: 10124.5 K8ZZ Hamilton/White, IL CW 1952Z  
DX de W6RK: 3556.5 K8ZZ Wabash, IL CW 2051Z

Everything before the colon is fixed (DX de W6RK). The frequency is at most 7 characters, could be less. The call (K8ZZ) can be anywhere between 4 to 8 characters. Then the county name. The "/" between two counties means that station is on a 2 county line. Then the 2 state code, mode (CW) This could be SSB, and then the time in Zulu.

My previous DX clusters all have fixed lengths for output, but I'm assuming if there is a trick to this last one, I could apply it to the previous outputs. Even if the objects have trailing blank spaces before or after the value, I'm assuming there is a way to trim those spaces before sticking them in a database.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2020 23:11 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/13 "2020-12-23T23:11:41Z")

</div>

> [@aa0z](#):
>
> The 4th has a variable length with the county, 2 letter state, mode and the time.

Off the top of my head, you can do a conditional if () else (you will need to identify somehow which data you are working with. Perhaps the IP address?

```auto
if(deviceIP = "the_ip_of_the_odd_device") {
    //split the string like this
} else {
    //split the string like that instead
}
return msg;

```

> [@aa0z](#):
>
> Even if the objects have trailing blank spaces before or after the value, I'm assuming there is a way to trim those spaces before sticking them in a database.

search "mdn string trim"

[example](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)

You can even test it in the browser to see how it works.

---

<div class="post-metadata">

**Author:** ![aa0z](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aa0z](https://discourse.nodered.org/u/aa0z)\
**Post date:** [24 December 2020 03:36 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/14 "2020-12-24T03:36:04Z")

</div>

Picture is worth 1000 words here...thanks for taking the time to help me through this. Learning more and more as I go here.

Two flows.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca825521d9f5eae59d14551fffe5f2b4e7828929.png)

For the top flow the output looks like this ;

```auto
DX de NX5M-#: 14030.0 FS5GL CW 20 dB 24 WPM CQ 1543Z
DX de K3PA-#: 3553.5 WR5U CW 8 dB 16 WPM CQ 1800Z
DX de K7VIC: 14076.0 OH8EZA 1800Z
DX de K0GU: 50313.0 XE2TT DN70MQ<ES>DL44UC CQ 1801Z
DX de N5RZ-#: 10121.9 VE6JZN CW 8 dB 14 WPM CQ 1852Z
DX de KO7SS-#: 7029.3 K9ZO CW 18 dB 36 WPM CQ 1852Z

```

Everything is nice and even...and I can break it up with the substr call because the frequency and call are pretty much in the same place. I'm just grabbing the frequency, the call sign and time in zulu. If I get all the comment, great. It's not a priority. The substr call is in the function node and the object looks like the below. I've got some work to do to clean up the spaces, possibly with the trim command.

```auto
let spot = msg.payload
let freq = spot.substr(17,7);
let call = spot.substr(26,6);
let comment = spot.substr(54,15);
let time = spot.substr(70,4);
return {payload:{freq:freq,call:call,comment:comment,time:time}};

```

The formatted object looks like this ;

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc8b85bc5659327e2dc8bd1b8c5d29f5aeb630e5.png)

Now on to the bottom flow. Here is the output from that flow.

```auto
DX de W6RK: 3556.5 K8ZZ Hamilton/White, IL CW 1947Z
DX de W6RK: 7056.5 K8ZZ Hamilton/White, IL CW 1950Z
DX de W6RK: 10124.5 K8ZZ Hamilton/White, IL CW 1952Z
DX de W6RK: 3556.5 K8ZZ Wabash, IL CW 2051Z
DX de W6RK: 7056.5 K8ZZ Wabash, IL CW 2056Z
DX de W6RK: 3556.5 K8ZZ Posey/Vanderburgh, IN CW 2211Z
DX de W6RK: 7056.5 K8ZZ Posey/Vanderburgh, IN CW 2217Z
DX de W6RK: 10124.5 K8ZZ Posey/Vanderburgh, IN CW 2220Z

```

The first part is formatted nicely, but once you get into the frequency, all bets are off. The freq starts at position 13, but might be 7 characters, it might be 6 characters, a space then the call sign then a string with a state at the end, the mode then the time in zulu. For this flow, I need to capture the frequency and everything after into an object.

That is my roadblock at the moment.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 February 2021 03:36 UTC](https://discourse.nodered.org/t/connecting-to-a-telnet-server-displaying-the-contents/37895/15 "2021-02-22T03:36:05Z")

</div>

Closed on 22 February 2021 03:36 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
