How to scan all devices on local network using flutter - flutter

I am facing a problem with my flutter application I want to get a list of nearby devices on my same network for android 10 and below I am running this command using Process.run: ip neigh show however this command seems to be forbidden on android 11 and above as it always returns
Cannot bind Netlink socket: Permission denied
and not returning anything I tried the arp-scanner to check if it will work and to my luck, it worked but it has some data missing I need to get IP Address, MAC Address and Hostname the previous flutter plugin only return the IP addresses and always return null for the mac address.
If anyone has any suggestions on how to do this please help.

Google has removed the possibility to bind netlink socket to retrieve arp table from targetSdkVersion 30 through SELinux policies.
Without using bind function, I've made a library that does a workaround that consist in sending via netlink socket a type message not listed (30) and then I've used the socket receive to see which data system returns to that socket. From that, I've noticed that the received data was the arp table.
I do not know if this library works with flutter, but you can try it out.
You can find more here https://github.com/fulvius31/ip-neigh-sdk30/blob/main/ipneigh30/src/main/cpp/ip_neigh.c

Related

How to change port of Dart HTTP request?

I'm writing a Flutter application which involves getting some data from an HTTP server. Here's my code:
// the local IP of my testing server
final String SERVER = 'http://192.168.1.13:5000';
class Database {
Future<String> _getJob(int jobID) async {
var response = http.get('$SERVER?jobID=$jobID');
return response.body;
}
}
Currently this is the output:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception:
SocketException: OS Error: Connection refused, errno = 111, address =
192.168.1.13, port = 41966
Obviously this is happening because there isn't anything on port 41966, but the request shouldn't be going to that port, it should be going to port 5000. Is there a different way of specifying the port?
(my async code probably isn't very good, i'm going to work on it once i've figured this out)
Please specify which platform (Web, iOS, Android, Windows, Linux, mac, Flutter is amazing 😅) you're using. Its probably because Android/ iOS do not allow HTTP connections as they can be read by others on the same network. You need to use HTTPS.
I think for debugging, its better if you just called an API that already exists. Pick one from here: https://apilist.fun/ Then in the future, you can figure out how to get a TLS/SSL certificate assigned to your server (e.g. Using LetsEncrypt)
Alternatively you can go into the configuration of your application (platform specific config) to allow insecure connections (HTTP). For example, on Android and on iOS. However, Android and iOS default to this to make sure you consider security, not just send your data in plain text.
Note: its not actually because the server doesn't exist or the port is wrong. If the server didn't exist, it would say something like connection timed out or server unreachable. In your case, your OS/ platform immediately tells you OS Error: Connection refused, because it can see you're using HTTP.
I had the same issue.
Try using ngrok or a similar proxy. I think the dart HTTP client picks a random port when the host is not resolvable.
If you are pushing to an mobile device for testing your app, there is probably no reason a local IP address will be resolved.

Popup page without internet connection using coova-chilli

I am using openwrt and coovachilli for registration purpose, when there is presence of internet connection to router then chilli starts and popup page appears after connect to WiFi.
But I want popup page without presence of internet. Router should popup after connect to WiFi using coovachilli without internet. Please help me out in this situation.
Thanks in advance.
OpenWrt Version:- 15.05
CoovaChilli Version:- 1.3.0
It's not possible technically due to the way Coova Chilli (and other hotspot software systems) works.
Without Internet connection, your DNS server will return failures so no DNS query will work. Without DNS queries (and IP addresses as result), there won't be a HTTP request for Coova to hijack. Your device (eg. iPhone) won't even trigger a CNA window
There are possibilities (workarounds) of course - eg. make your DNS resolver (dnsmasq?) resolve to some dummy/hardcoded IP address while the connection is down. You would have to write a script yourself that detects connection and swaps configs
It is possible with a workaround.
You have to use a local UAM server (on the same host or LAN) and authenticate with local users file or local RADIUS server. For using local users file, without RADIUS server, you must specify a dummy RADIUS server IP:
radiusserver1 127.0.0.1
localusers /etc/chilli/localusers
Then, you can add a dummyuser:dummypass to your localusers file and use it for the authentication as usual:
http://${uam_ip}:${uam_port}/logon?username=dummyuser&password=${chap_password}

How to find all the available MIDI ports over network using CoreMIDI?

I am working on an app which needs to send Midi over wifi. I looked at CoreMIDI and the MIDINetworkSession class. I have set the default session's policy to .anyone and also enabled it. But I am not clear what to do next. I looked at PGMidi but it didn't list out the remote host's MIDI ports after making changes to the session.
What I want is a list of all the MIDI ports that I can connect to on the remote machine running MacOSX.
Is it even possible? Can someone please give me some hints?
I was able to figure it out. Here is what I did:
Scanning the remote service
Suppose my mac is running a MIDI session which is advertised over Bonjour. I used NetServiceBrowser to scan the local network and find out which server supports "_apple-midi._udp" service. Look at the documentation.. NetServiceBrowserDelegate receives a service in the delegate callbacks. Please note that the service object is not yet resolved against the DNS and therefore doesn't contain IP address of the host.
The next step is to resolve the service by using a NetServiceDelegate. The service object passed in the success delegate callback contains everything that is there to know about that service. So now, you have a list of IP addresses/hostnames and corresponding port numbers.
Sending MIDI
Create a MIDINetworkConnection instance using the ip address/hostname and the port number. It looks like a synchronous call, so may be it doesn't contact the server itself. Next, get all the midi devices and iterate over Entities and Destinations. Its given in this document

.gethostbyaddr() does not work on all devices. Why? (Python)

I wrote a script that goes through all local IPs in the '0' network (192.168.0.*).
I use a loop with socket.gethostbyaddr(ip_modified_by_the_loop_each_time).
The loop returns me 3 devices their hostnames.
Now, I found that it does not find 4 devices (at least).
It does wind my Windows Laptop, not my Android Phone. It does find
one MacBook, not the iMac, not the other MacBook. It also does not
find any phone.
I know that all the devices are online and have an IPv4 address.
I can ping them very well, it responds just fine. But when I use socket.gethostbyaddr(ip_modified_by_the_loop_each_time) it throws an error.
I used a try:/except: statement to get around the error, but it still can not find my phone by IP and get the hostname, but I know it is there.
I am using python 3.3
Why is that happening, how to fix that?
Thank you.
gethostbyaddr tries to find out the hostname for a given IP address by using either locally stored information (i.e. /etc/hosts) or doing a reverse DNS lookup. The result does not depend on the host being online or not, they only depend on the availability of these information.
And these information can also not be trusted. For example the DNS operator of a domain could add the following records:
test.example.com A public.ip.of.test
public.ip.of.test PTR localhost.
In this case a lookup (gethostbyname) of test.example.com would return the IP address of this host while a reverse lookup (gethostbyaddr) would claim that the hostname is localhost. And if the PTR record would be missing gethostbyaddr would fail, even if the host is online.
See also wikipedia: reverse dns lookup.

Bluetooth: how to create a socket for connecting to a service with specific UUID with Bluez?

I am working with the BlueZ libraries for managing the bluetooth stack under linux. I am trying to open a socket that should connect with a specific service whose UUID is known. I have successfully tried to open sockets between a server and a client following the examples here:
http://people.csail.mit.edu/albert/bluez-intro/c404.html
where it is also described how to explore services in a remote host; however, what I cannot figure out is how to specify the UUID while connecting the socket. This is something quite straightforward on other contexts, as it happens when using Android libraries; however, with BlueZ I haven't found examples on the web.
Thanks for the help!
Stefano
-- added some details in a reply... don't know if it's right or not; if not, sorry
thanks for your help!
In my post I said I wanted to connect a socket with a specified UUID since I had in mind a function like createRfcommSocketToServiceRecord as can be found in:
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord%28java.util.UUID%29
which returns a socket given a certain UUID. I am developing two softwares, one being the client and the other the server, therefore it's a service I am creating, not a standard one. I publish such service on the server with a specified UUID, and I would like to connect to it from the client. The server is running fine, since with an android platform, exploiting the mentioned createRfcommSocketToServiceRecord method, I am able to connect to the server with the right service.
The example you posted is very clear as well, but unfortunately it is in Python, while (I forgot to point out) I am using Bluez as a C library. I am able to exploit the SDP and inspect services on a remote server; however, when it is the time of setting up the socket, I don't see how to specify the port. I thought about the rc_channel, but as far as I understood it is the bluetooth channel (ranging from 1 to 11 or something similar). Could you please point out Where I should be able to specify the port while creating the socket in the client? And where am I able to find the right port in the complex structure the sdp is dealing with? -- referred to:
http://people.csail.mit.edu/albert/bluez-intro/x604.html
Thanks again for the help!
You don't connect sockets by UUID. You use a socket to connect to remote device and browse its SDP to discover the UUIDs it offers, and map that to a socket port. Here's an example of this process using PyBluez, python wrappers above BlueZ
http://people.csail.mit.edu/albert/bluez-intro/x290.html