简体   繁体   中英

SMPP server - How to get the client (ESME's) IP address?

I'm using https://github.com/farhadi/node-smpp in order to create a smpp server.

I'm going to forbid connection if the client's IP address is not in the allowed ips list. For that when a new connection is open I have to check if the credentials are ok and if the IP address is a good one.

The question is how and where can I get the client (ESME's) IP address?

  session.on('bind_transceiver', function(pdu) {
    session.pause();
    
    const username = pdu.system_id;
    const password = pdu.password;
    const ipAddress = ''; // WHERE TO GET IT??

    if (credentialsAreOk(username, password, ipAddress)) {
      session.send(pdu.response());
      session.resume();
    } else {
      session.close();
    }
  });

When an ESME is connecting to your server, a session is created.

The network socket used by this TCP connection, which is a net.Socket class ( https://nodejs.org/api/net.html.net_class_net_socket ), is stored inside this session in the socket property.

const socket = session.socket;

So you can easily access this socket property of the session and get the remoteAddress (the clients IP) from there ( https://nodejs.org/api/net.html.net_socket_remoteaddress ).

const ipAddress = session.socket.remoteAddress;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM