Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong IP for usb0 #185

Open
mguilherme opened this issue Apr 28, 2019 · 5 comments
Open

Wrong IP for usb0 #185

mguilherme opened this issue Apr 28, 2019 · 5 comments

Comments

@mguilherme
Copy link
Contributor

So I had to change the usb ip in order to have an internet connection with a Mac, everything is working just fine after changing /etc/network/interfaces to:

iface usb0 inet static
    address 192.168.2.2
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 192.168.2.1

However the Tyny Cloud is showing the wrong ip for the USB-Ethernet because the ip is hardcoded in ~/launcher/Menu/GameShell/98_TinyCloud/__init__.py.
I wrote a small function to retrieve the IP from USB0, therefor we could replace the hardcoded ip with the result of this function, if no one changes the ip, fine :) If we need to change the TynyCloud will be always updated.

The function:

import socket
import fcntl
import struct

def GetIpAddress(ifname):
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

  try:
    ip = socket.inet_ntoa(fcntl.ioctl(
       s.fileno(),
       0x8915,  # SIOCGIFADDR
       struct.pack('256s', ifname[:15])
    )[20:24])
  except:
    ip = 'x.x.x.x'

  return ip


print(GetIpAddress('usb0'))

Do you want me to create a PR or do you have anything to add / change?

@cuu
Copy link
Contributor

cuu commented May 5, 2019

it would be great to have a PR from you
and thanks

@AresLiCa
Copy link

I haven't looked into the code much, but I realized the same issue. I wonder if this is associate with connecting the pi using USB to PC or it means the connection to a micro usb Ethernet dongle. Thanks!

@AresLiCa
Copy link

@mguilherme is gateway 192.168.2.1 your router ip?

@mguilherme
Copy link
Contributor Author

@AresLiCa no its not, this is related to USB connection!

@AresLiCa
Copy link

@mguilherme Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants