How to return client IP address in loopback 4

0 votes

I want to return either IPv4/IPv6 IP in the loopback4 application? How do I modify the below code to get IP address?

import {get, param} from '@loopback/rest';

    export class GreetController {       
      @get('/', {
        responses: {
          '200': {
            description: 'greeting text',
            content: {
              'application/json': {
                schema: {type: 'string'},
              },
            },
          },
        },
      })
      greet(@param.query.string('name') name: string) {
        return `hello ${name}`;
      }
    }
Feb 24, 2022 in Cyber Security & Ethical Hacking by Edureka
• 12,690 points
852 views

1 answer to this question.

0 votes

You should also add this code in server.js to grant the real ip, otherwise you´re getting the load balancer IP:

app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);

Hope this will help!

For more, enroll in Cyber security masters program today.

Thank you!

answered Mar 2, 2022 by Edureka
• 13,620 points

Related Questions In Cyber Security & Ethical Hacking

+1 vote
1 answer

How to find IP address of nodes in my network?

The IP address of the nodes connected ...READ MORE

answered Feb 9, 2019 in Cyber Security & Ethical Hacking by Omkar
• 69,210 points
4,229 views
0 votes
1 answer
0 votes
1 answer

How to find MAC address using IP address?

To find the MAC address, run this ...READ MORE

answered Feb 9, 2019 in Cyber Security & Ethical Hacking by Omkar
• 69,210 points
2,006 views
0 votes
1 answer

How to diagnose a network using loopback address?

C:\Users\priyj_kumar>ping Loopback Pinging DESKTOP-TGAB9Q5 [::1] with 32 bytes ...READ MORE

answered Mar 22, 2019 in Cyber Security & Ethical Hacking by Priyaj
• 58,090 points
1,321 views
0 votes
1 answer

how to change your ip address?

Try using the following code. This the most ...READ MORE

answered Feb 21, 2022 in Cyber Security & Ethical Hacking by Edureka
• 12,690 points
482 views
0 votes
1 answer

How can I force the login to a specific ip address?

Try to access the router's default page. It's ...READ MORE

answered Feb 15, 2022 in Cyber Security & Ethical Hacking by Edureka
• 12,690 points
1,114 views
0 votes
1 answer

How do i check a ip address range whether it falls in Class A,Class B,Class C

class NetworkId{ static String findClass(String str){ int index = ...READ MORE

answered Feb 16, 2022 in Cyber Security & Ethical Hacking by Edureka
• 13,620 points
604 views
0 votes
0 answers

How to get Wi-Fi router IP address on iOS?

Is there any way to get Wi-Fi ...READ MORE

Feb 16, 2022 in Cyber Security & Ethical Hacking by Edureka
• 12,690 points
406 views
0 votes
1 answer

how to find ip address in cmd

1. Open the Command Prompt.   a. Click the Start icon, ...READ MORE

answered Feb 9, 2022 in Cyber Security & Ethical Hacking by Edureka
• 13,620 points
46,264 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP