Exposing local api inside WSL to physical devices and emulators - windows

I'm working on a react native app from a windows 10 computer. I installed WSL, set up my backend needs on it, and I can see my api responding on localhost from windows, no problem on that end.
Now I would like to call it from my mobile app - both from an android emulator using Android Studio and from my physical android device (using Expo) connected to the same local network over wifi.
Using Ngrok it could work, exposing my localhost to a public url, but that's not what I'm looking for. I want it all to remain local if possible. My pc's local ipv4 is 10.0.0.8, but nothing comes out on that address (not from the mobile app neither from my desktop browser, which works when using localhost).
My Ubuntu inside WSL says:
~$ cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 JB-PC.localdomain JB-PC
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
My ipconfig:
Carte Ethernet Ethernet :
Suffixe DNS propre à la connexion. . . : Home
Adresse IPv6 de liaison locale. . . . .: fe80::f04e:ae2b:40b9:3d82%6
Adresse IPv4. . . . . . . . . . . . . .: 10.0.0.8
Masque de sous-réseau. . . . . . . . . : 255.255.255.0
Passerelle par défaut. . . . . . . . . : 10.0.0.138
Carte Ethernet vEthernet (WSL) :
Suffixe DNS propre à la connexion. . . :
Adresse IPv6 de liaison locale. . . . .: fe80::68c3:25c9:588a:a957%17
Adresse IPv4. . . . . . . . . . . . . .: 172.20.32.1
Masque de sous-réseau. . . . . . . . . : 255.255.240.0
Passerelle par défaut. . . . . . . . . :
localhost pings on ::1 :
C:\WINDOWS\system32>ping localhost
Envoi d’une requête 'ping' sur JB-PC [::1] avec 32 octets de données :
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms
Statistiques Ping pour ::1:
Paquets : envoyés = 4, reçus = 4, perdus = 0 (perte 0%),
Durée approximative des boucles en millisecondes :
Minimum = 0ms, Maximum = 0ms, Moyenne = 0ms
and 127.0.0.1 pings as well, and pinging localhost with -4 option gives the same output:
C:\WINDOWS\system32>ping 127.0.0.1
Envoi d’une requête 'Ping' 127.0.0.1 avec 32 octets de données :
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Statistiques Ping pour 127.0.0.1:
Paquets : envoyés = 4, reçus = 4, perdus = 0 (perte 0%),
Durée approximative des boucles en millisecondes :
Minimum = 0ms, Maximum = 0ms, Moyenne = 0ms
What should I do to make this work?

So I found a solution thanks to https://superuser.com/a/1618446/757755 I successfully used option 2 and used port forwarding, with the script found here. Remember that your PowerShell script has to be ran as administrator.

Here's the quick & dirty way: simply run npx expose-wsl#latest before starting the expo dev server.
Disclaimer: I'm the author of the package ;-)
See the expose-wsl github repo for more info.

Related

How to get last default gateway from a windows command file

In This Question a script is presented to capture the last default gateway. (Another solution is shown to capture the first gateway, but I want the last one.
The script is:
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Default"') do set ip=%%b
set ip=%ip:~2%
echo.
echo The Gateway is: %ip%
echo.
Given this ipconfig input (some details removed for privacy):
Ethernet adapter Ethernet 2:
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 10.1.251.148
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0
Ethernet adapter Npcap Loopback Adapter:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::****:a19b:****:bf4%15
Autoconfiguration IPv4 Address. . : 169.254.11.244
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . : ev***.li****.io
Link-local IPv6 Address . . . . . : fe80::a**:c4**:c**1:dfa3%14
IPv4 Address. . . . . . . . . . . : 10.100.17.34
Subnet Mask . . . . . . . . . . . : 255.255.248.0
Default Gateway . . . . . . . . . : 10.100.16.1
Ethernet adapter Bluetooth Network Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
c:\>
The output result is:
c:\>for /F "tokens=1-2 delims=:" %a in ('ipconfig|find "Default"') do set ip=%b
c:\>set ip= 0.0.0.0
c:\>set ip=
c:\>set ip= 10.100.16.1
c:\>set ip=0.100.16.1
c:\>echo.
c:\>echo The Gateway is: 0.100.16.1
The Gateway is: 0.100.16.1
c:\>echo.
As the for loop iterates, it has the correct gateway address on the third iteration, but then a fourth iteration overwrites it with and incorrect value with the first digit truncated. I'm not sure why there is a fourth iteration since the word Default is present three times.
Why does this happen?

Powershell: get DHCP status with Get-NetIPConfiguration?

I'm a powershell newbie.
If I run Get-NetIPConfiguration -Detailed I can see the IPv4 DHCP status. This is a good start - took me a lot of googling to get this far:
PS C:\Windows\system32> Get-NetIPConfiguration -Detailed
ComputerName : VM-172-26-39-24
InterfaceAlias : Ethernet
InterfaceIndex : 6
InterfaceDescription : Red Hat VirtIO Ethernet Adapter
NetCompartment.CompartmentId : 1
NetCompartment.CompartmentDescription : Default Compartment
NetAdapter.LinkLayerAddress : FA-16-3E-FF-0D-60
NetAdapter.Status : Up
NetProfile.Name : Network
NetProfile.NetworkCategory : Public
NetProfile.IPv6Connectivity : NoTraffic
NetProfile.IPv4Connectivity : Internet
IPv6LinkLocalAddress : fe80::x:x:x:x
IPv4Address : 172.26.39.249
IPv6DefaultGateway :
IPv4DefaultGateway : 172.26.36.1
NetIPv6Interface.NlMTU : 9000
NetIPv4Interface.NlMTU : 9000
NetIPv6Interface.DHCP : Enabled
NetIPv4Interface.DHCP : Disabled
DNSServer : x.x.x.x
x.x.x.x
But if I run something like
Get-NetIPConfiguration -Detailed | select InterfaceAlias,NetIPv4Interface.DHCP
I get an empty field?
PS C:\Windows\system32> Get-NetIPConfiguration -Detailed | `
select InterfaceAlias, NetIPv4Interface.DHCP
InterfaceAlias NetIPv4Interface.DHCP
-------------- ---------------------
Ethernet
Am I doing something wrong?
If I remove the trailing .DHCP ("what's in there?") I see nothing recognisable
PS C:\Windows\system32> Get-NetIPConfiguration -Detailed | select InterfaceAlias, NetIPv4Interface
InterfaceAlias NetIPv4Interface
-------------- ----------------
Ethernet MSFT_NetIPInterface (Name = "#55?55;", CreationClassName = "", SystemCreationClassName = "", SystemName = "")
You need to calculate the sub property when used in a Select statement:
Get-NetIPConfiguration -Detailed | `
select InterfaceAlias, #{N="DHCP";E={$_.NetIPv4Interface.DHCP}}
Or try this:
Get-NetIPConfiguration | Select -ExpandProperty NetIPv4Interface | Select InterfaceAlias,DHCP
...or you could just retrieve the config, put it in a variable then get the desired sub-properties:
$Config = Get-NetIPConfiguration
$Config | forEach {
[pscustomobject]#{InterFaceAlias=$_.InterFaceAlias;DHCP=$_.NetIPv4Interface.DHCP}
}

Windows 7 routing issue

I'm really stuck on this one and I have been told stack over flow is a great place to come for advice.
I have a machine running Windows 7 Professional with two internal gigabit NICs.
I have enabled IP routing using the registry key "IPEnableRouter", setting it to 1.
This is the output of ipconfig:
C:\Users\testlab>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : testlab-PC
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : Yes
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : goose.com
Ethernet adapter Local Area Connection 4:
Connection-specific DNS Suffix . : goose.com
Description . . . . . . . . . . . : D-Link DGE-528T Gigabit Ethernet Adapter
Physical Address. . . . . . . . . : 00-64-01-73-A8-4G
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.1.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . : 10.10.10.2
NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : goose.com
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
Physical Address. . . . . . . . . : B1-AE-C9-1A-59-13
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 172.16.65.65(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . : 172.16.0.254
DNS Servers . . . . . . . . . . . : 172.20.220.26
10.10.10.2
NetBIOS over Tcpip. . . . . . . . : Enabled
Tunnel adapter Local Area Connection* 11:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Tunnel adapter isatap.bskyb.com:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : goose.com
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Routing table:
C:\Users\testlab>route print
===========================================================================
Interface List
17...00 24 11 83 a8 4D ......D-Link DGE-528T Gigabit Ethernet Adapter
11...b3 ae D5 1A 19 79 ......Realtek PCIe GBE Family Controller
1...........................Software Loopback Interface 1
12...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
14...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 172.16.0.254 172.16.65.65 266
127.0.0.0 255.0.0.0 On-link 127.0.0.1 306
127.0.0.1 255.255.255.255 On-link 127.0.0.1 306
127.255.255.255 255.255.255.255 On-link 127.0.0.1 306
172.16.0.0 255.255.0.0 On-link 172.16.65.65 266
172.16.65.65 255.255.255.255 On-link 172.16.65.65 266
172.16.255.255 255.255.255.255 On-link 172.16.65.65 266
192.168.1.0 255.255.255.0 On-link 192.168.1.1 266
192.168.1.1 255.255.255.255 On-link 192.168.1.1 266
192.168.1.255 255.255.255.255 On-link 192.168.1.1 266
224.0.0.0 240.0.0.0 On-link 127.0.0.1 306
224.0.0.0 240.0.0.0 On-link 172.16.65.65 266
224.0.0.0 240.0.0.0 On-link 192.168.1.1 266
255.255.255.255 255.255.255.255 On-link 127.0.0.1 306
255.255.255.255 255.255.255.255 On-link 172.16.65.65 266
255.255.255.255 255.255.255.255 On-link 192.168.1.1 266
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 172.16.0.254 Default
===========================================================================
IPv6 Route Table
===========================================================================
Active Routes:
If Metric Network Destination Gateway
1 306 ::1/128 On-link
1 306 ff00::/8 On-link
===========================================================================
Persistent Routes:
None
I've set this up on a couple of machines before years ago and it worked fine, I guess I am just forgetting something, but it is driving me crazy now.
From the 192.168.1 network I can ping 192.168.1.1 and 172.16.65.65, but not any of the other hosts on the 172.16 network. So all the hosts in the 192 network have no access.
I've even tried enabling the routing and remote access service, but that made no difference.
I'm tried with all firewalls disabled as well to ensure it wasn't being blocked.
When I trace a ping from 192. to the internet it gets to 172.16.65.65 and then never moves on, it is like the machine just won't forward the packets on, but I do not know why.
Any advice or things to try would be very appreciated and if you need anymore information let me know.

Skip multiple lines in a batch script

I want to print out only a certain line from the output of a command.
Lets take the example of ipconfig command. This returns a lot of lines.
Windows IP Configuration
Wireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : ab80::456d:123e:5ae5:9ab6%15
IPv4 Address. . . . . . . . . . . : 192.168.1.33
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter Local Area Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
I want to just print say the 11th line.
I tried the following
FOR /F "skip=10 delims=" %G IN ('IPCONFIG') DO #ECHO %G
This skips only the first 10 lines and prints the rest of the lines.
Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter Local Area Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
How do I print only the 11th line?
Just leave the loop
FOR /F "skip=10 delims=" %G IN ('IPCONFIG') DO #ECHO %G & goto done
:done
edited Get the 11th line in the output of a command from a single command line
for /f "tokens=1,* delims=:" %a in ('ipconfig^|findstr /n "^"^|findstr /l /b /c:"11:"') do echo %b
Execute the command, number the output, retrieve the required line, split the initial number and echo the rest
set "x=1" & for /f "skip=10 delims=" %a in ('ipconfig') do #(if defined x (set "x=" & echo %a))
Set a flag variable, execute the command, skip the first 10 lines and for each line if the flag is set, clean the flag and echo the line
Could I run this in a single command? I mean not through a batch file. yes:
ipconfig |find "Default Gateway"
(runs both on the command line and in a batch file)

virtualbox win7 host debx64 guest networking issues

Firstly, I had a stable VM working fine, then upgraded to the latest virtualbox edition and things went bad. First my .vdi crashed and could not be re-imported, so I downgraded to 4.1.4 that was working fine. I have duplicated the previous build from a deb amd64 business card iso.
The build went find with the guest fetching all required dependencies from the web no problem. However on restart I am having problems with the networking.
initially I could ssh into 192.168.56.112, however an apt-get returned network un-reachable. I could not ssh into the other IP's.
So I did a little digging and deleted the 70-persistent-net.rules, rebooted and now a different permutation.
I can now ssh in via a dhcp address on adapter 3 (192.168.20.104), DNS seems to work fine with apt-get fetching.
I can start a session on adapter 4 as soon as ssh requests Log in it terminates connection and will not re engage.
The local IP's 192.168.56.x refuse connection as well.
After 3 days and multiple re-installs I still cant get this thing to do a basic config as I had it working before, any help is appreciated,
thx
Art
my set up is a s follows,
adapter 1 => host-only (intel pro/1000 T server (82543GC)
Adapter 2 => NAT (intel pro/1000 T server (82543GC)
Adapter 3 => bridged (intel pro/1000 T server (82543GC) //bridged to : [Ethernet adapter Local Area Connection:]
Adapter 4 => bridged (intel pro/1000 T server (82543GC) // bridged to : [Ethernet adapter Local Area Connection:]
70-persistent-net.rules
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:a7:b9:b2", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:ae:b0:9b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio_net)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:1b:16:b4", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:38:85:3a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"[/code]
interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.56.112
netmask 255.255.255.0
broadcast 192.168.56.255
allow-hotplug eth1
iface eth1 inet dhcp
allow-hotplug eth2
iface eth2 inet dhcp
allow-hotplug eth3
iface eth3 inet static
address 192.168.20.112
netmask 255.255.255.0
broadcast 192.168.20.255
ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:ae:b0:9b
inet addr:192.168.56.112 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feae:b09b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:468 (468.0 B)
Interrupt:9 Base address:0xd240
eth1 Link encap:Ethernet HWaddr 08:00:27:1b:16:b4
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe1b:16b4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1699 (1.6 KiB) TX bytes:1152 (1.1 KiB)
eth2 Link encap:Ethernet HWaddr 08:00:27:a7:b9:b2
inet addr:192.168.20.104 Bcast:192.168.20.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea7:b9b2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3284 (3.2 KiB) TX bytes:1138 (1.1 KiB)
eth3 Link encap:Ethernet HWaddr 08:00:27:38:85:3a
inet addr:192.168.20.112 Bcast:192.168.20.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe38:853a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:87 errors:0 dropped:0 overruns:0 frame:0
TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10846 (10.5 KiB) TX bytes:11466 (11.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)
ipconfig of host
Windows IP Configuration
Host Name . . . . . . . . . . . . : tosx500
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Mixed
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Local Area Connection 10:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : TAP-Win32 Adapter V9
Physical Address. . . . . . . . . : 00-FF-6A-96-C7-8E
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Ethernet adapter Local Area Connection 6:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Loopback Adapter
Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::f139:e3f3:81f4:cb87%20(Preferred)
Autoconfiguration IPv4 Address. . : 169.254.203.135(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
DHCPv6 IAID . . . . . . . . . . . : 654442572
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-13-B2-35-4A-C8-0A-A9-0D-C5-90
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
Wireless LAN adapter Wireless Network Connection 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
Physical Address. . . . . . . . . : 70-F1-A1-04-70-B5
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Wireless LAN adapter Wireless Network Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek RTL8191SE Wireless LAN 802.11n PCI-E NIC
Physical Address. . . . . . . . . : 70-F1-A1-04-70-B5
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Atheros AR8131 PCI-E Gigabit Ethernet Controller
Physical Address. . . . . . . . . : C8-0A-A9-0D-C5-90
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::3593:4f1f:e8a5:9468%11(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.20.103(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::204:edff:fea9:39c%11
192.168.20.1
DNS Servers . . . . . . . . . . . : 192.168.20.1
NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter
Physical Address. . . . . . . . . : 08-00-27-00-4C-76
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.56.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . : 192.168.20.1
NetBIOS over Tcpip. . . . . . . . : Enabled
Tunnel adapter Teredo Tunneling Pseudo-Interface:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
You might need to create a network bridge on Windows 7 in order to bridge the virtual NICs with the physical ones. It's a bit tricky to setup bridged networking with VirtualBox (VMware does this auto-magically). Think I just added both adapters to a bridge and enabled DHCP for it (if I remember correctly). Just in case: use WireShark to see what's really going on.
This worked for me, on Windows host machine.
Configure your network adapter to
1) Allow the network adapter to wake the computer,
2) Allow a magic packet to wake the computer,
3) Allow IPV6
http://www.worldstart.com/dropped-internet-connection-in-sleep-mode/
Now, I can sleep and wake my machine, and both the guest and host will have networking, not just the host.

Resources