laravel ip

From the moment you publish a website, you need to be wary of security. From hackers to script-kiddies, you can’t always be sure of where the next attack could come from.

从发布网站的那一刻起,您需要警惕安全性。 从黑客到脚本骗子,您始终无法确定下一次攻击的来源。

So, as developers, we are always on the prowl for the next best thing when it comes to protecting our website(s).

因此,作为开发人员,在保护我们的网站方面,我们总是竭尽所能。

In this article, we will cover a simple way of how we can use IP intelligence to detect unwanted connections and protect against insecure requests.

在本文中,我们将介绍一种简单的方法,说明如何使用IP智能来检测不需要的连接并防止不安全的请求。

什么是IP智能 ( What is IP Intelligence )

When most people hear IP intelligence, the thing that comes to mind is “locating users from their IP address”. But, it doesn’t stop there, IP intelligence can be used to accomplish many things:

当大多数人听到IP智能时,想到的就是“从其IP地址定位用户”。 但是,这还不止于此,IP智能可以用来完成许多事情:

  • Content personalization.内容个性化。
  • Currency detection.货币检测。
  • Fraud prevention.预防诈骗。
  • Time Zone lookup.时区查询。
  • Language redirection.语言重定向。

The list above is just a handful of things that can be achieved using IP intelligence.

上面的列表只是使用IP智能可以实现的一些事情。

Building a service that can do all the things listed above can take a lot of time and resources. So, instead of building and managing such a service, that’s what the sponsor IPAPI of this article does.

构建可以完成上面列出的所有功能的服务可能会花费大量时间和资源。 因此,本文的发起者IPAPI就是在构建和管理这样的服务,而不是在这样做。

入门 ( Getting Started )

Our firewall will be built as a middleware for our application, meaning a request coming into our app will pass through this “filter” and reject suspected bad actors.

我们的防火墙将作为应用程序的中间件构建,这意味着进入我们的应用程序的请求将通过此“过滤器”并拒绝可疑的不良行为者。

For demonstrating how we could build a simple middleware to protect our apps, we will be creating a Laravel project. Note, the same can be done in any programming language of choice

为了演示如何构建简单的中间件来保护我们的应用程序,我们将创建一个Laravel项目 。 注意,可以在任何选择的编程语言中完成相同的操作

composer create-project laravel/laravel firewall --prefer-dist

So, head over to IPAPI and create an account. After that, you’ll see a secret key that has a similar structure to 86ebc30b4adfc508e48bf1b489140fe3. Grab whatever your own is and add it to your `.env` file.

因此,转到IPAPI并创建一个帐户。 之后,您将看到一个与86ebc30b4adfc508e48bf1b489140fe3具有相似结构的秘密密钥。 随便抓什么,然后将其添加到您的.env文件中。

@media (max-width: 1280px) { .go-go-gadget-react img:first-child { display: none; } }@media (max-width: 780px) {.go-go-gadget-react { flex-direction: column; }.go-go-gadget-react img { margin-left: 0 !important; margin-bottom: 12px !important; }.header-thingy { margin-top: 20px; }.button-thingy { margin-left: 0 !important; margin-top: 12px !important; }} @media (max-width: 1280px) { .go-go-gadget-react img:first-child { display: none; } }@media (max-width: 780px) {.go-go-gadget-react { flex-direction: column; }.go-go-gadget-react img { margin-left: 0 !important; margin-bottom: 12px !important; }.header-thingy { margin-top: 20px; }.button-thingy { margin-left: 0 !important; margin-top: 12px !important; }}

IPAPI_ACCESS_KEY=86ebc30b4adfc508e48bf1b489140fe3

After that open config/services.php and add the following array value.

之后,打开config/services.php并添加以下数组值。

'ip' => ['key' => env('IPAPI_ACCESS_KEY'),
],

The last thing to do is to install GuzzleHttp which will be used to make a request to IPAPI’s server.

最后要做的是安装GuzzleHttp ,它将用于向IPAPI的服务器发出请求。

composer require guzzlehttp/guzzle

After that, we can then build our middleware.

之后,我们可以构建中间件。

向IPAPI的服务器发出请求 ( Making a Request to IPAPI’s Server )

So, IPAPI offers two endpoints for us to use.

因此,IPAPI提供了两个端点供我们使用。

  • api.ipapi.com/api/<ip> where we provide the IP we want to check.api.ipapi.com/api/<ip> ,其中提供了我们要检查的IP。
  • api.ipapi.com/check will guess the incoming IP address and give a response (good for requests coming from the browser.api.ipapi.com/check将猜测传入的IP地址并给出响应(对于来自浏览器的请求很有用。

We are most interested in the first one because using the second one will retrieve the IP of our server instead of the incoming request. So, using the first one, we can capture the user’s IP and forward it to IPAPI.

我们对第一个服务器最感兴趣,因为使用第二个服务器将检索服务器的IP而不是传入请求。 因此,使用第一个,我们可以捕获用户的IP并将其转发到IPAPI。

After we create a request like:

创建请求后,如下所示:

GET https://api.ipapi.com/api/161.185.160.93?access_key=86ebc30b4adfc508e48bf1b489140fe3

The response will look something like this

响应将如下所示

{"ip": "161.185.160.93","hostname": "161.185.160.93","type": "ipv4","continent_code": "NA","continent_name": "North America","country_code": "US","country_name": "United States","region_code": "NY","region_name": "New York","city": "Brooklyn","zip": "11238","latitude": 40.676,"longitude": -73.9629,"location": {"geoname_id": 5110302,"capital": "Washington D.C.","languages": [{"code": "en","name": "English","native": "English"}],"country_flag": "http://assets.ipapi.com/flags/us.svg","country_flag_emoji": "												

laravel ip_使用IP智能保护Laravel站点相关推荐

  1. laravel api_如何在现有的Laravel应用中获取即时GraphQL API

    laravel api by Karthikeya Viswanath 通过Karthikeya Viswanath 如何在现有的Laravel应用中获取即时GraphQL API (How to g ...

  2. 实战:使用TCP/IP筛选保护服务器安全

    使用TCP/IP筛选保护服务器安全 对于部署在Internet的服务器,安全是必须要考虑的事情.为了降低服务器受***的危险,停止不必要的服务或在本地连接的TCP/IP属性中只打开必要的端口. 如图2 ...

  3. 区块链公证和知识产权(IP)保护应用场景

    前面文章谈到了区块链公证和知识产权(IP)保护的原理,今天来谈谈应用场景. 存在性证明 存在性证明是最早的区块链鉴证服务,通过网络,可以为如何数字资产做证明.哈希证明文件内容,时间戳证明文件是什么时候 ...

  4. Laravel框架01:composer和Laravel简介

    Laravel框架01:composer和Laravel简介 一.Composer介绍 二.创建Laravel项目 三.Laravel目录结构 四.Laravel启动方式 一.Composer介绍 c ...

  5. 使用主机ip地址绑定GooglAppEngine站点

    使用过GoogleAppEngine的同学大概都知道,在Eclipse环境下,如果运行Google Web Project,那么他将自动绑定到LoalHost:8888 然后,我们可以通过本机浏览器输 ...

  6. Laravel 教程 - Web 开发实战入门 ( Laravel 5.5 )购买链接

    Laravel 教程 - Web 开发实战入门 ( Laravel 5.5 )购买链接: 推荐给你高品质的实战课程 https://laravel-china.org/courses?rf=15818 ...

  7. php laravel 加载css,Laravel无法加载css文件(Laravel can't load css file)

    Laravel无法加载css文件(Laravel can't load css file) 我无法在Laravel项目中加载css文件. /public/css/style.css确实存在IDE确认, ...

  8. laravel ajax ip,怎么在Laravel中利用AJAX动态刷新部分页面

    怎么在Laravel中利用AJAX动态刷新部分页面 发布时间:2021-02-17 13:12:43 来源:亿速云 阅读:119 作者:Leah 怎么在Laravel中利用AJAX动态刷新部分页面?很 ...

  9. laravel简易根据ip限制接口请求

    如果会用redis优先redis,不行就用cache 中间件示例: <?phpnamespace App\Http\Middleware;use Closure; use Illuminate\ ...

最新文章

  1. 准IT工作者如何择师、如何学习
  2. Windows核心编程 第十九章 DLL基础
  3. Elasticsearch的或且非及其组合
  4. Java22-day13【Lambda表达式(标准格式、练习、注意事项)、接口组成更新(默认-静态-私有方法)、方法引用(构造器)】
  5. Visual Studio 2008 单元测试
  6. 图片链接生成器软件_推荐10个小众但是黑科技十足的Windows软件
  7. 编辑距离及编辑距离算法
  8. EMOS 如何停止反病毒和防垃圾邮件功能
  9. Shell 更好看的回显
  10. static和extern对函数的作用
  11. Opencv--Mat类型ROI的设置
  12. ubuntu安装minisat_minisat 安装指南
  13. 2008江西高考0分作文
  14. datatables 树形表格 java数据组装_实学:Java开发自己的博客系统-第三十篇(后台添加栏目功能-4)...
  15. 2020-10-28网络安全之网络安全产品
  16. ar面部识别_AR人脸识别数据集
  17. ReactOS实践(一) ReactOS 源代码编译以及VMWare下运行
  18. WebAPI第四天学习总结—— 常见网页特效案例(轮播图、节流阀、返回顶部、筋斗云案例)
  19. 手机上有哪些超棒超实用的APP让你觉得相见恨晚
  20. C语言建立循环单链表并输出

热门文章

  1. 再增加一些英语学习网址
  2. P2P打洞服务器与客户端
  3. 第一篇第二章火灾的基础知识
  4. Oracle查询部门工资最高员工的两种方法 1、MAX()函数 2、RANK()函数
  5. 10分钟自制胡同儿老味道,堪比米其林丨空姐亲测
  6. 2021年道路运输企业安全生产管理人员复审考试及道路运输企业安全生产管理人员证考试
  7. 计算机考研复试真题 简单计算器
  8. java 数组元素依次右移,将数组元素循环右移k个位置(Java实现)
  9. python写微信小程序商城_Python(Django 2.x)+Vue+Uniapp微信小程序商城开发视频教程
  10. 零基础无实物一步一步学PLCS7-1200仿真(七)-led灯闪烁-定时器或系统时钟