0

So I'm looking to try and get my foot into chrome extensions and had an idea, but I don't know if it is possible. What I need is to get some basic information of the user's internet connection, the network's name for example, that could easily be differentiated from one connection to another.

What I'm looking to do is to open different tabs when starting up google chrome depending on what network the user is connected to. For example, if the user is connected to their home network it could open things like facebook or youtube, as opposed to work related websites when connected to their work network.

All I've been able to find so far is to check whether or not a connection exists with JS, so I'm tempted to say it's not possible, but is there some way to accomplish this ? Again, I'm new to chrome extensions so I don't really know of all the possible things I can do.

Dalannar
  • 381
  • 1
  • 2
  • 11
  • You could also use local IP addresses instead of public addresses, see https://stackoverflow.com/questions/18572365/get-local-ip-of-a-device-in-chrome-extension/29514292#29514292. – Rob W Apr 28 '15 at 14:21

2 Answers2

0

There are lots of ways to do this, you can use the network information API with

NetworkInformation.connection 

which is supported in chrome.

do something like

var connection = navigator.connection || navigator.webkitConnection;

this will give you access to a boolean (which you already have) or a value.

But I think what you're looking for is to IP detect, because the range would be the same for their "home network" the network itself, the network name, and data wouldn't be available to a clientside code like JS. You could use a deferred language like Python and get it hooked up with PyJamas.

http://pyjs.org/

EDIT: Alternatively try using Node. Yes this is serverside, but there are resources for implementing it for chrome extensions. By using the network module you can sniff out lots of different information such as

network.get_private_ip(function(err, ip) {
  console.log(err || ip); // should give you the users public IP, to help find out where they are
})

or use

network.get_interfaces_list(function(err, list) { }

to get something like

name: 'eth0',
ip_address: '10.0.1.3',
mac_address: '56:e5:f9:e4:38:1d',
type: 'Wired',
netmask: '255.255.255.0',
gateway_ip: '10.0.1.1'
pj100
  • 402
  • 3
  • 13
  • Are you sure chrome supports it ? According to https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/connection#Browser_compatibility it doesn't and I don't seem to be able to get it to work. As for pyjs I tried it but couldn't seem to get it to work. Just need to sit down for a bit and learn it I guess, but I don't have time right now. – Dalannar Apr 27 '15 at 22:17
  • webkit does support it, but it is experimental. If you're looking for a legit solution here and PyJamas isn't working out for you, I would highly suggest looking into node.js. I use this to build large applications, and it runs serverside so you can get this info. See my edit above. – pj100 Apr 28 '15 at 14:01
0

I've found a way, although it relies on a third party service. http://www.hostip.info (and I'm sure many others) has a simple API to get the network's IP address, and so a simple XMLHTTPRequest does the job.

I'm still looking for ways that I don't have to rely on someone else (and also not setting up an online service myself like hostip.info), but for now this will work.

Thanks to pj100 for reminding me that the network's IP address could work just as well, I'm embarrassed that I didn't think of it before.

Dalannar
  • 381
  • 1
  • 2
  • 11