Weird TCP messages coming into my flow

Hi. Thanks for reading my post. I'm having great luck as a newbie with node-red overall for a project that I'm working on. The one thing I can't seem to figure out is a strange message that comes every now and then from the open TCP port. I'm using custom hardware to send TCP messages, a twelve character string. I've added a function node to try to filter out any of the other messages:

var data = msg.payload;
var len = msg.payload.length;
if (len === 12) {
    msg.payload = data;
    return msg;
}

It only passes the valid messages intermittently. I am wondering if I have messed up the syntax. Any help would be greatly appreciated. Thank you again for reading.

Also the strange messages coming in look like this:

GET / HTTP/1.1

Host: 161.35.101.114:49153

Connection: close

Accept-Encoding: gzip

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Hi @ifiififiifiif

Welcome to the forums!

This is not a "strange" TCP Message per se :sweat_smile:
This is a browser request.

if I navigate to https://duckduckgo.com
The server @ duckduckgo.com will receive something very simular.

According to the user agent, the following browser is accessing this resource.
Chrome 50 on Mac OS X.

if you have accessed this TCP server through the mentioned browser at some point, its likely trying to ascertain some info about it to help with its "recent" viewed websites or something to that effect.

What you are seeing, is the RAW TCP request sent by a web browser.
The browser will likely freakout, as its expecting a valid HTTP/1.1 response.

In a nut hell: The above browser is accessing http://161.35.101.114:49153/

Host : 161.35.101.114:49153
URI : /
Method : GET

Sure I get that. But this is not a standard HTTP port so they’re crawlers. It sort of doesn’t matter what they are or why they are I just need to figure out how to filter them out. I’m using two ports for TCP and they both get messages from crawlers. It seems to be happening more and more often. Any thoughts on why this function mode isn’t working consistently? Any ideas on a general method of filtering out messages from crawlers? Thanks.

Ahh I see.

On the basis you should not be receiving HTTP requests.
If your TCP IN node is set to output a string.

In a function node connected to the output of the TCP IN node...

const Blocked = ["GET","POST"]
const Header = msg.payload.substring(0, 4).trim().toUpperCase()

if(!Blocked.includes(Header)){
   return msg
}

if outputting a buffer it should be just as trivial.
just check the first 4 bytes for a pattern.

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