Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
MAC address using uuid.getnode()
-
Sorry, I know this is not a Pythonista question directly, but it relates.
I really want to make a directory in site-packages directory for files my apps/scripts create. But I want this across devices. Thinking that I will publish the scripts for use.
I thought about creating a directory in the site packages using the MAC address, then the app would make a sub dir in here. The decimal form of the MAC address. The documentation is ambiguous to me wether or not I could consistently rely on the result on the same device. I have tried many different combos , like airplane mode, no wifi, no cell data only Bluetooth. VPN activated etc..
The result is consistent regardless for what I have tested.I think on a desktop it's a lot more problematic, with the different interfaces possible.
Would love to hear from anyone if they think this is a safe way to get a reproducible result for a single device
from uuid import getnode print getnode()
-
The result will be different when you restart the app. It's basically a random number (which is consistent with the documentation, as starting a sub process to determine the hardware address is not possible on iOS).
-
@omz , thanks. With all my tests, was the one thing I didn't do, restart Pythonista. I can see you are right though. It does change as you say.
Is there another function/method you can think of that would yield the same result every time on a single device I can use as a dir name. Needs to be consistent -
@omz , maybe you are wondering why in hell do I want to do this. But the site-packages dir can get out of control pretty quickly. As everything in there is being stored at root level of the dir.
I just think it would be nice if apps created a dir under a std dir in the site-packages if there apps need to save config info etc...
Yeah, I know I go on and on... -
You can get your device's name:
str(objc_util.ObjCClass('UIDevice').currentDevice().name())
Which mean's you need to give your devices unique names, but that doesn't seem too objectionable.
You could also use
str(objc_util.ObjCClass('UIDevice').currentDevice().identifierForVendor().UUIDString())
Which I haven't tested through reboots, but this is supposed to be the Apple approved way of getting unique id's. It does not survive remove/reinstalls apparantly. Of course, you could generate your own random uuid, and store it in the keychain -- either way you need to know this in advance before you can deploy anything. Storing your own would make you robust to changes in identifierForVendor across ios versions.
-
@JonB , this thread is 10 months old. Just off the top of your head do you know if your last response is still valid?
On the latest py3 beta (today's release, and iOS 10.02) your code listed below works.
But if possible what I would like to know, does the returning uuid contain anything that could be broken down and be used in a malicious way. Eg, uuid1 contains the hardware network address (I guess for the current network adapter, but I am not sure.)Anyway, my reason too look at this again is a little different.
It's about if I wrote a small app in pythonista that would talk to a web hosted simple bottle app. And let's say all the app did was present a topic you could vote on. The app would send the response the the bottle app. But of course like to limit the votes to a certain question to one per user (lossley speaking). So I was thinking using the function you showed to do that.I think the biggest issue is if someone was to hit the button in my app after I shared it in the Forum , are they sharing any details that could be exploited. Of course I would not, but it's not the point. So, that's what I am after, a way to identify a user without receiving any compromising data.
I am not trying to make a cheat proof system, just something semi reasonable that identifies a user without compromising their security and without having to ask for user names etc.
I have mentioned before, I think it would be a great idea if Pythonista had a in built API KEY with a module that could do some handshaking and access/connect dialogs same as iOS modules, photos/contacts etc...
I addressed this to @JonB as he provided the solution in the thread, for a different but related question. But happy to hear from anyone on this subject. As it involves people's security(my own included), I am only looking for Well understood solutions. I understand a few things from reading, but not enough. Like I know uuid4 is safe as it's totally random. But does not help like a cookie. Also I read about UDID which seems to be depreciated now. I guess that also had security flaws.
Anyway, i hope I can get a safe answer to this question. I think many here could benefit from the answer alsoimport objc_util id = str(objc_util.ObjCClass('UIDevice').currentDevice().identifierForVendor().UUIDString()) print(id)
-
The id is unique to each device/vendor, as i understand it. I guess it depends on what you mean by safe.
-
@JonB , by safe I just mean if I stored those ids from people using my pythonista script app and someone got their hands on those ids, is there anything they could do with them. Like target the user on an email spam list by doing some funky reverse look up in a database or anothing else that compromises that Id
-
@Phuket2
https://developer.apple.com/reference/uikit/uidevice/1620059-identifierforvendor
lets the developer track a device, but on its own does not link to any user info (once you provide account info to an app, then obviously it is linked, for the developer only)So probably safer than most other info people nave already shared
-
@JonB , thanks. Yeah, it appears great for a reasonably robust way to identify let's say an entity. Interesting reading the article. I ran the function of the py3 beta and the py2 beta, and I got the same result as the article says you will as it's from the same vendoer. I have saved the result to see if it changes next time I do a beta update. It says it may or may not. I have 3 installs of omz software (editorial, py3 beta and py2 beta) It doesn't really matter, just interested. This way seems pretty good for pythonista scripts.