Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi.
I want to develop a small application that runs on my computer and detects when my phone is within range.
The idea is to have the program scan every 30 seconds or so to simply check if I am around or not.
Do you think this is doable in a relatively easy and simple way?

I found a bluetooth lirary for C# called inthehand from 32feet.

Thanks for your feedback
Simmi
Posted
Updated 8-Sep-12 8:50am
v2
Comments
ridoy 9-Sep-12 7:27am    
Of course it is possible..set your bluetooth searching technique for every 30 seconds interval.when 30 second passed,it again starts searching for devices.It is possible and you may also find code for it.
Member 10676658 15-Aug-14 5:55am    
hi i can you share me how u did this to me?, as i wanted it for my final year project ,
it will be very thankful

Hi there,

I'm not sure if you're asking whether this is possible, and if so how to do it, or just asking if it's a good idea. Whether it's a good idea or not depends on what you're trying to do with it (which you haven't said). It is certainly possible to simply poll your USB Bluetooth chip for what devices are currently in range (should be one of the easiest things to do, especially if you have found a library for doing it) and then simply check in that list for your device. It should be simple and easy.

However, it is very fundamentally flawed if you are wanting to use this as a reliable way for detecting your presence. It is probably easiest to get a list of device names that are within range. However, this would allow any device with the same name as yours to look exactly like yours, thus spoofing your presence. You may be able to get a list of device Ids instead, but that is susceptible to the same problem (Id spoofing). So this really isn't a good idea if you are trying to use it for security purposes etc.

If your phone is a smart phone you could write an app for it that will communicate with your computer when it is in range and use public key/private key encryption and your own certificates system for your phone/computer. Unfortunately this is then neither simple nor easy.

Hope this helps,
Ed

Oh by the way, I looked up the library you are using. Here's the documentation page that you want: http://32feet.codeplex.com/wikipage?title=Discovery&referringTitle=Documentation[^]

Just convert the samples from VVB.Net to C# - not very hard...
 
Share this answer
 
v3
Comments
sigsand 8-Sep-12 16:32pm    
The security issue is almost not a factor. It's just that sometimes when I am in class and I leave the classroom (for lunch or something) I forget to lock my computer.
I simply want to make it so that my computer locks itself when I leave for lunch or something.

I have made an application now that scans every XX seconds/minutes, puts all the devices in range into a List and then goes through the List checking if my device is one of them. It works, but now I just found out that even if I turn off my bluetooth radio on my phone the application (or probably the computer itself) remembers my phone and displays it also since I paired my phone to my computer.

If I do NOT pair my phone to my computer then my computer won't see my phone unless I press a button on my phone that tells my phone to be visible for 2 minutes.

I am not sure how to get around this.
Ed Nutting 8-Sep-12 16:46pm    
I'm sorry you appal me! Security is not an issue you just want to use it to make sure your computer locks so that people can't access it? Security is most certainly an issue.

Let me try and explain this to you simply. I'm 16 from London UK. I am still a student. Lets suppose I am a student at your school, in your class and as a keen programmer and techy person I notice what your doing. All I then have to do is spoof your device then turn my Bluetooth on before you leave. Hey presto when you forget to lock your computer it will still look like you're nearby (as my phone will be spoofing your's) and guess what - I now have complete access to all your files and all of that supposedly "private" information that I shouldn't be able to access.

I wouldn't do this, because I am a good person, but there are plenty of people my age who would and could. Security IS an issue for you - otherwise what do you classify locking a computer as??

As for your other problem, it sounds like you are scanning for paired devices not available devices which is why you are having problems. Given that you MUST now write the program I suggested (to fix your security holes) you can assume that if your phone is in range, it will be connected and identified with your program. Therefore, simply have a timer in your program that sends your phone a message every 30s. If no response is received then your phone is no longer in range and the computer should be locked. Do not unlock your computer by walking back in range - another security hole that you may introduce. Also, you MUST use public key/private key encryption such as SSL over your Bluetooth connection before identifying the device else it would be just as easy for someone to man-in-the-middle attack your connection and thus still spoof your phone.

Please have some respect for the fact that you are supposed to be protecting your student's private data. I don't know about the US, but in the UK there have been far too many leaks of private/confidential data - especially through phone hacking (you may have heard about the Murdoch scandal?)

Please, either do not do this, or take the time to develop it properly/securely. Thanks,
Ed
sigsand 8-Sep-12 17:43pm    
Thanks for the detailed and long answers.
You are taking it to far..
I can see how someone would be able to do a man-in-the-middle attack and pretend to be me if I simply scanned for the name of the device since multiple devices can have the same name but I use devices ID. Anyways..

"Please have some respect for the fact that you are supposed to be protecting your student's private data." I am not sure what you mean by this. I am making this software for myself. Noone else.

So now my phone is paired to my computer and I the solution that I want to implement will be something in the direction you said. Sending a message every 30s or so to see if it gets an answer. Even better if I figure out how to do it encrypted.

I appreachiate that you point out that it requires some type of security but I am rather asking how to do it at all, not how to do it well. The security issues can be implemented later.

Thanks
Ed Nutting 8-Sep-12 17:54pm    
I understand that you are doing this for yourself. However, the aim, I presume, of locking your computer is to prevent your students (or anyone other than you) from accessing your account. Therefore, you need your computer to lock reliably and you need to make sure other people can't get access simply by spoofing your phone. When I said "have some respect..." what I meant was, respect the fact that you have the responsibility to make your account (and thus your student's private information/records that you hold about them) secure and that, therefore, you must make your program secure. A common mistake for people to make is to say "oh well we'll build security in later" but that often doesn't work. It is best to build security in from the outset. That way, everything remains secure.

To do this at all should imply doing it well.

Anyway, so long as you implement security before actually using this then that is okay.
Ed

(P.s. Also, please use CP commenting/threading properly. Use the Reply button to respond to posts, don't start a new thread by using the "Have a Question or Comment?" link.)
sigsand 9-Sep-12 6:42am    
Did not see the reply button.

"respect the fact that you have the responsibility to make your account (and thus your student's private information/records that you hold about them) secure" I hold no such information. I am not a professor or a lecturer. I am a student myself.

But back to the question I asked please.
Is there someone who knows the libray called 32feet or inthehand that could help me out a little?
I want to send a small message to my phone every 30 seconds or so. If I don't get a reply then that means the phone is out of range.

List<device> devices = new List<device>();
InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices();
int count = array.Length;
for (int i = 0; i < count; i++)
{
Device device = new Device(array[i]);
devices.Add(device);
}

foreach(Device d in devices)
{
if (d.DeviceInfo.ToString().Equals("myphonesdevicenumber"))
{
Guid MyServiceUuid
= new Guid("{00112233-4455-6677-8899-aabbccddeeff}"); // found this somewhere not sure what the string represents.

byte[] guidbytearray = d.DeviceInfo.ToByteArray(); // guid as a byte array.
string guidstring = d.DeviceInfo.ToString(); //guid as a string.
Int64 guid64 = d.DeviceInfo.ToInt64(); // guid as an int64.

Guid g = new Guid(guidbytearray);




bc.Connect(d.DeviceInfo,MyServiceUuid);
// turnoff = false;
}
}

This compiles but throws an error: "The requested address is not valid in its context 6C8336E70FC2:00112233445566778899aabbccddeeff"
I have solved my question.
If anyone wants to do the same then take a look at this page: http://32feet.codeplex.com/wikipage?title=Testing%20if%20a%20device%20is%20in%20range&referringTitle=Documentation[^]

I have written a small application that does exactly what I want it to do.
About the security issues that Ed was pointing at: I am not sure if it is needed. I use my devices address hardcoded into the software.

Basically I have a timer set to XX seconds/minutes that runs the code on that webpages and tells if the device is in range or not.

If someone knows how that could be exploited, "hacked", please do tell me.

Thanks
 
Share this answer
 
Comments
Member 11014282 31-Aug-14 13:24pm    
if u dont mind can u pls help me in my final yr project. m also doing somthing similar..
pls help my doubt is that.. i paired my device then how will it found that my device is within range or not...
DaProgrammerr 20-Feb-15 6:22am    
Hi Sigsand Please i have the same issue ,, can u please snd me your code only the area where the device in range code is .. my email is kakerkhan@hotmail.com
regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900