Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get client IP in server application

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to get client-side IP in server-side applications. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

If there is a request header for x-forwarded-for, take the first IP, otherwise take the remoteAddr to establish a connection to the socket.

X-forwarded-for has basically become a standard HTTP header based on proxy. The format is as follows. You can see that the first IP represents its real IP. Please refer to MDN X-Forwarded-For [1].

X-Forwarded-For: 203.0.113.195, 70.41.3.18, 150.172.238.178

X-Forwarded-For:,

Here is how koa gets the IP

Get ips () {

Const proxy = this.app.proxy

Const val = this.get (this.app.proxyIpHeader)

Let ips = proxy & & val

? Val.split (/\ sstories,\ slots /)

: []

If (this.app.maxIpsCount > 0) {

Ips = ips.slice (- this.app.maxIpsCount)

}

Return ips

}

Get ip () {

If (! this [IP]) {

This [IP] = this.ips [0] | | this.socket.remoteAddress | |''

}

Return this [IP]

}

After reading the above, do you have any further understanding of how to obtain client-side IP in server-side applications? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report