how to know if a profile is connected to a wireless ntework with wlanapi - wlanapi

i can't found the function in wlan api to know if a profile is connected or not to a network.
WlanGetAvailableNetworkList gives only networks with profile associated.
Thansk for your help.

answer :
use WlanRegisterNotification
and check NotificationCode == wlan_notification_acm_connection_complete with
wlanReasonCode == WLAN_REASON_CODE_SUCCESS in structure WLAN_CONNECTION_NOTIFICATION_DATA

Related

How to set Ipv4 addresses with dbus-python (Hotspot and ethernet)

(fairly new to networking)
I'm trying to setup a small, yet somewhat complicated network settings on my ubuntu 18.04 machine.
The topology of the network: Ubuntu machine (called "the server") will act as the DHCP server for both hotspot and ethernet. connected to the ubuntu machine are 2 ubuntu machine clients and a camera.
I've implemented "the server" with python-dbus library, to set up/down a hotspot connection, which works as intended. but my problem is how to manage the ip addresses and the routing.
i'll elaborate on 2 problems i am facing:
in order to change the ipv4 address for the Hotspot AP, i found out i could edit a file: "/etc/NetworkManager/system-connections/", adding another line: "address1=X.Y.Z.W" (my desired ip address).
but editing the file isn't the proper way for my requirements, i would rather do it from the code itself. which changes do i need to make to the code in order to make the same changes?
this is how the code connection object of dbus looks like:
def get_hotspot_struct(iface, uuid, ssid, password):
s_con = dbus.Dictionary({
'type': '802-11-wireless',
'uuid': uuid,
'id': 'PixellotHotspot',
'interface-name': iface,
})
s_wifi = dbus.Dictionary({
'ssid': dbus.ByteArray(ssid.encode()),
'mode': 'ap',
'band': 'bg',
'channel': dbus.UInt32(1),
})
s_wsec = dbus.Dictionary({
'key-mgmt': 'wpa-psk',
'psk': password,
})
s_ipv4 = dbus.Dictionary({
'method': 'shared',
})
s_ipv6 = dbus.Dictionary({
'method': 'ignore',
})
con = dbus.Dictionary({
'connection': s_con,
'802-11-wireless': s_wifi,
'802-11-wireless-security': s_wsec,
'ipv4': s_ipv4,
'ipv6': s_ipv6,
})
logger.info('Getting hotspot connection template')
logger.info(con)
return con
Can i do the same for ethernet wired connections?
so far what ive figured is that I can edit "/etc/netplan/01-netconf.yaml" in order to set dhcp to false, and se an ip "X.Y.Z.W" (desired) for ethernet interface eth0.
but that seem to only work on the server, when i connect the ubuntu clients with ethernet wire to the server, the server wont give the clients any ip at all.
It does for the hotspot, but not for the ethernet.
I know my problem is very specific and all-over-the-place, but i would appreciate any help. Post here/sendme email/ Facebook me(Yves Halimi) if you have knowledge about this issue. Will compensate help!!
The D-Bus API is documented in man nm-settings-dbus.
To NetworkManager, it's always about creating connection profiles and activating them. So if you have code that can create one profile, another profile works basically the same -- just some keys will be different.
I find it helpful to use one of the other NetworkManager clients, and compare with what they do. For example, you could also just create the profile with nmcli connection add type ..., then get the D-Bus path via nmcli -f all connection show and finally, look at how the profiles looks on D-Bus:
busctl -j call org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Settings/1 org.freedesktop.NetworkManager.Settings.Connection GetSettings
See examples upstream: python+dbus
Maybe you'll find it easier to use python + pygobject + libnm. In that case, see examples here. The main downside is that you'll have an additional dependency (pygobject). libnm isn't an additional dependency, you'll already have that if you use NetworkManager.

Sending to another user with e-mail address

I am trying to create a script in Python to transfer funds to another Coinbase user when all I have is an e-mail address. I have been unsuccessful so far. How do I get another user's "id" when all I have is their e-mail address?
As a follow on, can I add a memo/note to the transfer? If so, how?
Finally figured it out with a little bit more searching and trial and error. For anyone else who may have this question:
First get the account ID for the currency you want to send.
account_list = client.get_accounts()['data']
ETH_id = [acc['id'] for acc in account_list if acc['balance']['currency'] == "ETH"][0]
Then use the send_money function (not transfer_money) to send to an e-mail address.
client.send_money(ETH_id,to="<e-mail address>", amount="0.0005", currency="ETH", description = "Hey look, it worked.")
The description keyword is for the memo.

Target email address validiation

Before the client sends a new email, he/she specifies one or more (To) destination addresses. Is there any way to check the validity of these emails before sending the message ?
Define "validity".
This JavaMail FAQ entry might help.
The InternetAddress class only checks the syntax of the address. The InternetAddress class is not able to determine whether the address actually exists as a legal address. It is not even possible to verify the host name if the application is running behind a firewall or isn't currently connected to the Internet.

Getting more info from snmp traps

I have some Windows PCs sending snmpt traps to a linux server. On the server a snmptt trap handler, that works fine except for one issue.
Windows sends out traps with a description (say "Adobe Flash player update service stopped"). My problem is I don't know how to receive this description. Using snmptt (link to doc page), I only get the trapoid,community, category, uptime, hostname, etc, but no description.
Problem is that the Windows trapOID only states that "a service has been stopped". You understand that this is not a very useful info.
With tcpdump I can see the trap coming:
> { SNMPv1 C=dst0pc10 { Trap(298)
> E:311.1.13.1.23.83.101.114.118.105.99.101.32.67.111.110.116.114.111.108.32.77.97.110.97.103.101.114 78.168.1.161 enterpriseSpecific s=1073748860 1213932 E:311.1.13.1.9999.1.0=49_6c_20_73_65_72_76_69_7a_69_6f_20_48_50_20_50_6f_72_74_20_52_65_73_6f_6c_76_65_72_20_e8_20_6f_72_61_20_69_6e_20_6d_6f_64_61_6c_69_74_e0_20_61_72_72_65_73_74_61_74_6f_2e_0d_0a
> E:311.1.13.1.9999.2.0="Unknown" E:311.1.13.1.9999.3.0="PCMAGA"
> E:311.1.13.1.9999.4.0="4" E:311.1.13.1.9999.5.0="0"
> E:311.1.13.1.9999.6.0="HP Port Resolver"
> E:311.1.13.1.9999.7.0="stopped" } }
I have big difficulties in understanding how to receive and log those descriptions. Any clue?
Ok, posting a question here usually boost my luck. I've found this simple answer:
In snmptt.conf file, the FORMAT directive could be set as
FORMAT $*
to put all the description in the "formatline" field of the database generated by snmptt.
Another problem arise, hope I can work it out soon: some descrption are in HEX format. Got to find a way to convert them.

allow users from specific static ip

We already completed the site. The problem is The site is having 3 logins .
one is the main super admin for the client
another two is for college admin .(Colleges will login here)
& their students. All the works are completed.
For example:
College IP:
172.16.4.1
172.16.1.101
This college should not be able to login except from this IP.
And there might be many college and each college can login only from there static IP.
will it be possible.
Thanks
Since there is no language mentioned, I give a sample in php
function canLogin() {
$allowed = array ('172.16.4.1', '172.16.1.101');
if (in_array ($_SERVER['REMOTE_ADDR'], $allowed)) return 1;
else return 0;
}
All you have to do is find the REMOTE_ADDR (user IP) and check if it is in approved list.
Note: It is possible to spoof remote address. But the above sample is simpler solution and better than nothing.

Resources