OSX Link Aggregation for USB tether and WiFi? - macos

Is this kind of link aggregation even possible?
On a Windows machine, there are several 3rd-party applications which make use of bonding and load balancing multiple network interfaces for increased throughput, such as Connectify Dispatcher, for example. Would it be possible to develop such an app for OSX? Is there already any 3rd-party software which does this on OSX? The closest thing I could find was IPNetRouterX, which I've failed to use for bonding USB and WiFi network interfaces.
I have also tried the following line in OSX's terminal:
sudo networksetup -createBond bond0 en1 en3
...where en1 is my WiFi interface and en3 is my USB network interface, which simply results in:
** Error: The parameters were not valid.
Likely, there would need to be some sort of Layer 2 "magic glue" to make this in any way a possibility... but primarily being a Windows programmer, I'm not sure if Apple would enjoy allowing that level of programming access, considering how proprietary they like to be...
Any idea what can be done here?

There are options to networksetup to tell you whether the OS can bond a particular port or not. To do so, you need to hand it a "hardware port", which you can find by using:
networksetup -listallhardwareports
Each of those, in turn, can be queried using
networksetup -isbondsupported <HW Port Name>
Bonded networks are set up using the networksetup port name, not the kernel interface name, so if you were to bond two ethernet networks, you would do so like this:
networksetup -createBond myBondedNet 'Ethernet 1' 'Ethernet 2'
Querying the ports on my 2009 MacPro running 10.9, I find only the hardware ethernet ports to respond YES to the -isbondsupported inquiry.
Note that I didn't have to have the port operational in order for -isbondsupported to return YES, so in my case both of my ethernets responded YES even though only one is currently connected.

gaige thanks for your technical answer but RectangleEquals is not asking how to do Link Aggregation through terminal but
IF Link Aggregation can work for USB, WIFI, or other type of internet connections.
The answer is NO.
Apple didn't created Link Aggregation. It's a separated feature Unix had. Therefore Apple has zero idea how to improve it - nor does it want to spent resource to figure it out because it is not a common enough demand. Even if it wants to give you the feature it will not provide in a regular version of OS X but will provide in a server version and charge you for it.
And there are developers who can do it, by writing a lot of codes - so no free version of such application exist. You can try Connectify Switchboard for OS X.

I found that there is actually no decent way of accomplishing this, thanks to the way that networking is handled via separate interfaces. Although it would be possible to use two separate interfaces to connect to the same remote data source, it would require kernel-level programming skills to get these two interfaces working in unison... And the packets returned through each separate interface would be handled VERY differently, and the network packets would be far too out of sync with each other... So even then, if you were to create some sort of magic bridge to handle all of these situations and somehow use two separate interfaces to pull the same synchronous data, it would end up being (best case scenario) the exact same speed -- but likely SLOWER -- than with just one network interface. Far too much hassle for almost zero benefit.

Related

How can I find, is any wifi router connected in my network

I am trying to develop an application for network monitoring. A part of this application is to detect "is any wifi router connected to any switches ports".
Basically, I have a mysql database table where I have all the mac addresses of devices(pc,wifi router,..) connected to each switch port(by SNMP). As far I know, first three bytes of mac address (Organizationally Unique Identifier - OUI) represent the vendor/manufacturer of the device. So, I want to make a list of all known vendors who manufacture wifi routers (Linksys,TP-LINK,Netgear,SMC,..) and make a match with the OUI to the mac addresses stored in database.
Q1. Is the solution correct? or what would be the appropriate way to solve this problem.
It would be a great help if any one suggest me what should be the appropriate way.
Thanks in advance
No, this is not an appropriate solution. For example, macOS allows a Macintosh to act as a Wi-Fi router via the Internet Sharing feature, but its Ethernet MAC address will still just have a regular Apple vendor prefix.
As already stated by Gordon Davisson you will be missing "Internet sharing"-constructions, so your results will be incomplete (i.e. False Negatives).
Another source of False Negatives could be wireless routers using NICs from a large generic vendor (think Intel).
Besides that; the OUI will tell you what the device's vendor is, but NOT what kind of device it is. It could, for instance, be a WIRED router, leading to results which are not, in fact, wireless routers (i.e. False Positives).
The big pain in the behind for your problem is that what you are trying to detect; a (wireless) router; shields certain data-traffic from clients behind from means of identification that would aid you in your query.

Wifi and LAN at same time

As the question states, I have two ethernet devices I need to use. A wifi hotspot for general traffic as well as a LAN connection for local traffic (192.168.1.*). Right now the wifi receives all traffic and disregards the existence of my local LAN devices. I am trying to communicate with this device using python's urllib2 and basic http fetches. The program works partially when I turn one or the other off (turning wifi off makes the LAN code work, and turning LAN off makes wifi/general traffic code work). I believe this is more of an operating system issue than a programming question, but I might be mistaken. I have been messing with the Ethernet setting in system preferences, but nothing has been working so far.
Thanks for the help.
Depending on your needs and degrees of freedom, you can:
1) Easiest: If you can control one or both network ranges, you can put wifi and LAN on different subnets. For example, 192.168.2.* could be LAN traffic, and 192.168.1.* could be wifi. If only the WiFi side has a gateway, then all traffic except 2.* traffic should route through WiFi, and all 1.* traffic goes to the LAN. No change to your computer.
2) Medium: if you don't control the networks, you can define routing rules for the two ports. This lets you say certain IP addresses should be reached thru wifi, vs others thru LAN port. An example in Linux, which I think should work on OS X too: http://linux-ip.net/html/routing-tables.html The trickiest thing is to make sure you won't get in the way when you're in someone else's network. You can do this by creating narrow routing rules, or turning them off when you don't need them. It sounds like you're doing this from a python program, so maybe the program could turn this on and off at start and finish.
3) Slightly more exotic: I wasn't totally sure from your question, but if you're trying to do load balancing (not separate networks), you could create rules to bond together two network ports and spread traffic across them. This isn't something I've done, but real network engineers know how to set this stuff up.
I could expand on one of these if you clarify what you're trying to do and what degrees of freedom you have.
For somebody don't want to do the study you can simply repeat my steps:
Open system preferences
click on Network
(ensure the precedence, first thunderbolt then wifi) click on thunderbolt
Configure IPv4 choose manually
delete router
done!
I have exactly the same user case. But I read this without any network knowledge.
I achieved this by simply following #Nils' 1) instructions. I only understand theses instructions after reading this link

How to figure out if the network the mac is connected to is a WiFi or cable network or the like

First off, you guys are all really helpful - thank you a lot!
Is there a way to figure out what type of network a Mac is connected to? WiFi? Cable? USB Modem? Any Cocoa / Foundation framework I can use to figure that out?
Thank you,
Matthias
You can tell whether the Mac is using WiFi, whether it is using a modem, and whether it is using hard Ethernet (which could be cable, DSL, or something else). Note that these are not mutually exclusive, there may be multiple connections of a single type (I have two Ethernet ports, for example), and that being connected to an IP network does not necessarily mean connection to the Internet.
You'll probably find the System Configuration API helpful. See also the framework reference.
You may also want to look at the source for HardwareGrowler in the Extras folder of the Growl source code.
You could ask for the route table and see what the default route is, that would tell you to some degree of accuracy what the active connection is.
This obviously has a lot to do with how you define 'some degree of accuracy'. Generally the main internet connection will also be the default route. I'm assuming you also want active connection to mean 'internet connection'.
netstat -rn
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.0.1 UGSc 22 14 en1
so for me, my default route goes out the en1 interface. I think you need to be a lot more specific on what you mean by 'active/current' means to you.
CAVEAT: just because my default gw is on en1, does not necessarily mean that's where all my inet traffic goes. (it happens to be true in my case, but don't count on it as truth, but would probably be correct more than half the time).

Win32 ,Multiple NIC computer , different DNS per NIC , how gethostbyname behaves?

On a win32 multiple nic computer, how to force DNS resolving through gethostbyname() on a specific nic if all nics have different DNS configured and have the same metric ?
Otherwise, how to know which DNS will be used to resolve names each time a gethostbyname() call will be performed by the application ?
You can't do this, at least I'm fairly certain you can't specify an interface to send out the queries from using gethostbyname() or any of the standard socket utilities. (There might be a very esoteric win32 option for this, but I'm betting against it)
If you absolutely need this functionality, you'll need to pick a third party DNS library that provides you with such an ability ... or even write one from scatch.
The library will need to provide you with a means of binding the UDP socket that will be issuing the DNS queries to a specified address.
There also might be a way of configuring Windows to issue DNS queries from an interface using system settings, but I strongly doubt there is a means of doing this from within a program.
That might be better answered at https://serverfault.com/ It's a site geared more toward administering a machine. SO is best for programming.
Consider to use raw sockets and implement your own DNS query mechanism.

How do you find out which NIC is connected to the internet?

Consider the following setup:
A windows PC with a LAN interface and a WiFi interface (the standard for any new laptop). Each of the interfaces might be connected or disconnected from a network. I need a way to determine which one of the adapters is the one connected to the internet - specifically, in case they are both connected to different networks, one with connection to the internet and one without.
My current solution involves using IPHelper's "GetBestInterface" function and supplying it with the IP address "0.0.0.0".
Do you have any other solutions you might suggest to this problem?
Following some of the answers, let me elaborate:
I need this because I have a product that has to choose which adapter to bind to. I have no way of controlling the setup of the network or the host where the product will run and so I need a solution that is as robust as possible, with as few assumptions as possible.
I need to do this in code, since this is part of a product.
#Chris Upchurch: This makes me dependent on google.com being up (usually not a problem) and on any personal firewall that might be installed to allow pinging.
#Till: Like Steve Moon said, relying on the adapter's address is kind of risky because you make a lot of assumptions on the internal network setup.
#Steve Moon: Looking at the routing table sounds like a good idea, but instead of applying the routing logic myself, I am trying to use "GetBestInterface" as described above. I believe what it should do is exactly what you outlined in your answer, but I am not really sure. The reason I'm reluctant to implement my own "routing logic" is that there's a better chance that I'll get it wrong than if I use a library/API written and tested by more "hard-core" network people.
Technically, there is no "connected to the Internet". The real question is, which interface is routeable to a desired address. Right now, you're querying for the "default route" - the one that applies if no specific route to destination exists. But, you're ignoring any specific routes.
Fortunately, for 99.9% of home users, that'll do the trick. They're not likely to have much of a routing table, and GetBestInterface will automatically prefer wired over wireless - so you should be good. Throw in an override option for the .1% of cases you screw up, and call it a day.
But, for corporate use, you should be using GetBestInterface for a specific destination - otherwise, you'll have issues if someone is on the same LAN as your destination (which means you should take the "internal" interface, not the "external") or has a specific route to your destination (my internal network could peer with your destination's network, for instance).
Then again, I'm not sure what you plan to do with this adapter "connected to the Internet", so it might not be a big deal.
Apparently, in Vista there are new interfaces that enable querying for internet connectivity and more. Take a look at the NLM Interfaces and specifically at INetworkConnection - you can specifically query if the network connection has internet connectivity using the GetConnectivity method.
See also: Network Awareness on Windows Vista
Unfortunately, this is only available on Vista, so for XP I'd have to keep my original heuristic.
I'd look at the routing table. Whichever NIC has an 0.0.0.0 route AND is enabled AND has the lowest metric, is the nic that's currently sending packets to the internet.
So in my case, the top one is the 'internet nic'.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.51 20
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.50 25
(much other stuff deleted)
Another alternative is to ping or GetBestInterface 4.2.2.2 - this is an old and venerable DNS server, currently held by GTEI; formerly by Sprint if I remember right.
Start > Run > cmd.exe (this works in XP and Vista): ipconfig /all
This displays all info about the interfaces in your computer. The "public" facing interface should have a public IP address. For starters, it should not be 192.168.x.x or 10.x.x.x :)
running traceroute to some public site will show you. Of course, there may be more than one interface that would get you there.
Look at the routing table? Generally, unless you're routing between the networks in windows (which is possible, but unusual for a client computer these days) the interface that holds the default route is going to have the Internet connection.
Your question didn't detail why or what you're doing this with so I can't provide any specifics. The command line tool "route" may be of some help, but there are probably libraries for whatever programming language you're using to look at the routing table.
You can't rely on the IP address of the interface (e.g., assuming an RFC-1918 address [192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8] isn't the internet) since most sites have some kind of NATed firewall or proxy setup and the "internet" interface is really on a "private" lan that gets you out to the Internet.
UPDATE: Based on your further information, it sounds like you have a decent solution. I'm not so sure about the choice of 0.0.0.0 since that's a boundary case for IP address -- might be OK on your particular mix of platform/language. Sounds (from the API description) like you could just specify an address, so why not some address known to be on the Internet, e.g. the IP address of your web site, or something more random like 65.66.67.68? Just make sure not to pick one of the rfc-1918 addresses, or the localhost range (127.0.0.0/8), or multicast, any other reserved range, and any address that resolves to a .mil or .gov (while it doesn't sound like getbestinterface sends any traffic, it would suck to find out by having the feds break your door down... :)
Looking at the network point of view, either could be routing to the "internet" at any time. If things like spanning tree protocol are enabled on a switch then you may find that what may have been the routing card to begin with may not be anymore.
Ping google.com though each NIC.

Resources