Skip to content

using webrtc, get client local ip by javascript in some browser, such as firefox, chrome and opera.

Notifications You must be signed in to change notification settings

bubifengyun/yii2-webrtc-get-client-local-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

通过 Webrtc 获得客户端本地 IP

Get Client Local Ip by Webrtc

博客原文:http://my.oschina.net/bubifengyun/blog/690253

示例代码,请勿用于生产环境!

Just a demo, Do not use in production envrionment!

由于网站只可以运行在局域网,随想获取本地 IP 地址,作为一个验证项。虽然可以通过设置假的 IP 来欺骗服务器,但也能在一定程度上做到仅限于特定IP的电脑访问。

适用于支持 WebRTC 的浏览器,比如火狐、谷歌等。且这些浏览器没有关闭 WebRTC 获得本地 IP 的功能。

using webrtc, get client local ip by javascript in some browser, such as firefox, chrome and opera.

安装

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist bubifengyun/yii2-webrtc-get-client-local-ip "*"

or add

"bubifengyun/yii2-webrtc-get-client-local-ip": "*"

to the require section of your composer.json file.

用法

Usage

Once the extension is installed, simply use it in your code by :

        <?= $form
            ->field($model, 'ip')
            ->widget(\bubifengyun\WebrtcGetClientLocalIp\WebRTCLocalIPWidget::className(), [
                'id' => 'loginform-ip',
                'hidden' => true,
            ]) ?>

Note

  • 'id' => 'loginform-ip', id was seen from source code.
  • id 是从浏览器查看源码看到的,暂时不会设置该 id

参考

Ref

About

using webrtc, get client local ip by javascript in some browser, such as firefox, chrome and opera.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published