mirror of
https://github.com/lupyuen/lupyuen.github.io.git
synced 2025-01-13 02:08:32 +08:00
Output MAC Address and Manufacturer Data
This commit is contained in:
parent
081a97f367
commit
77624bc567
3 changed files with 98 additions and 65 deletions
9
decode-base64/Cargo.lock
generated
9
decode-base64/Cargo.lock
generated
|
@ -7,8 +7,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
|
||||
|
||||
[[package]]
|
||||
name = "json-to-rss"
|
||||
name = "decode-base64"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"hex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "json-to-rss"
|
||||
name = "decode-base64"
|
||||
version = "0.1.0"
|
||||
authors = ["lupyuen <luppy@appkaki.com>"]
|
||||
edition = "2018"
|
||||
|
@ -8,3 +8,4 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
base64 = "0.12.3"
|
||||
hex = "0.4.2"
|
|
@ -1,80 +1,105 @@
|
|||
fn main() {
|
||||
let lines = std::fs::read_to_string("../../Downloads/20200704.txt").unwrap();
|
||||
let lines = std::fs::read_to_string("../../Downloads/20200705.txt").unwrap();
|
||||
let mut mac = Vec::new();
|
||||
let mut manu = Vec::new();
|
||||
for line in lines.split("\n") {
|
||||
// line contains b20200704-125008.txt: Value 7b226964223a2... | "{\"id\":\"nRZAdXp...Tg==\",\"mp\":\"SM-G970F\",\"o\":\"SG_MOH\",\"v\":2}"
|
||||
// println!("line = {:?}", line);
|
||||
if line.len() == 0 { continue; }
|
||||
if line.len() == 0 || !line.contains(":") { continue; }
|
||||
|
||||
let datetime = line
|
||||
.split(".")
|
||||
.collect::<Vec<&str>>()
|
||||
[0]
|
||||
.replace("b", "");
|
||||
// println!("datetime = {:?}", datetime);
|
||||
let line =
|
||||
line
|
||||
.splitn(2, ":")
|
||||
.collect::<Vec<&str>>()
|
||||
[1];
|
||||
if line.starts_with("Scan")
|
||||
|| line.starts_with("Connect")
|
||||
{ continue; }
|
||||
|
||||
// line contains Value 7b226964223a2... | "{\"id\":\"nRZAdXp...Tg==\",\"mp\":\"SM-G970F\",\"o\":\"SG_MOH\",\"v\":2}"
|
||||
// or Value 28dc2dfb72... | \"(\\xdc-\\xfb...\\xe8\"
|
||||
// or [49:b7:00:00:00:00] RSSI -96:
|
||||
// or Manu: FF03393161
|
||||
// println!("line = {:?}", line);
|
||||
if line.starts_with("[") {
|
||||
// line contains [49:b7:00:00:00:00] RSSI -96:
|
||||
let encoded = line
|
||||
.split(" ")
|
||||
.collect::<Vec<&str>>()
|
||||
[0]
|
||||
.replace(":", "")
|
||||
.replace("[", "")
|
||||
.replace("]", "");
|
||||
// encoded contains 49b700000000
|
||||
mac = hex::decode(encoded).unwrap();
|
||||
continue;
|
||||
}
|
||||
if line.starts_with("Manu: ") {
|
||||
// line contains Manu: FF03393161
|
||||
let encoded = line
|
||||
.split(" ")
|
||||
.collect::<Vec<&str>>()
|
||||
[1];
|
||||
// encoded contains FF03393161
|
||||
manu = hex::decode(encoded).unwrap();
|
||||
continue;
|
||||
}
|
||||
let encoded = line
|
||||
.split("==")
|
||||
.collect::<Vec<&str>>()
|
||||
[0]
|
||||
.to_string()
|
||||
+ "==";
|
||||
let encoded = encoded
|
||||
.split("|")
|
||||
.collect::<Vec<&str>>()
|
||||
[1];
|
||||
let encoded = encoded
|
||||
.split(":")
|
||||
.collect::<Vec<&str>>()
|
||||
[1]
|
||||
.replace("\\\"", "");
|
||||
let decoded = base64::decode(encoded.clone());
|
||||
// println!("datetime = {:?}", datetime);
|
||||
// println!("encoded = {:?}", encoded);
|
||||
// println!("decoded = {:?}", decoded);
|
||||
println!("{:?},{:?}", datetime, decoded);
|
||||
// Get the Base64 decoded value, or if not Base64 encoded, just dump the value
|
||||
let mut decoded = Vec::new();
|
||||
if encoded.contains("|") {
|
||||
if encoded.contains("id") {
|
||||
// encoded contains Value 7b226964223a2... | "{\"id\":\"nRZAdXp...Tg==
|
||||
let encoded = encoded
|
||||
.split("|")
|
||||
.collect::<Vec<&str>>()
|
||||
[1];
|
||||
// encoded contains "{\"id\":\"nRZAdXp...Tg==
|
||||
if encoded.contains(":") {
|
||||
let encoded = encoded
|
||||
.split(":")
|
||||
.collect::<Vec<&str>>()
|
||||
[1]
|
||||
.replace("\\\"", "");
|
||||
// encoded contains nRZAdXp...Tg==
|
||||
decoded = base64::decode(encoded.clone()).unwrap();
|
||||
}
|
||||
} else {
|
||||
// encoded contains Value 28dc2dfb72... | \"(\\xdc-\\xfb...\\xe8\"
|
||||
let encoded = encoded
|
||||
.split("|")
|
||||
.collect::<Vec<&str>>()
|
||||
[0];
|
||||
// encoded contains Value 28dc2dfb72...
|
||||
if encoded.contains("Value") {
|
||||
let encoded = encoded
|
||||
.splitn(2, "Value")
|
||||
.collect::<Vec<&str>>()
|
||||
[1]
|
||||
.replace(" ", "");
|
||||
// println!("encoded = {:?}", encoded);
|
||||
decoded = hex::decode(encoded).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
if decoded.len() > 0
|
||||
&& mac.len() > 0
|
||||
&& manu.len() > 0
|
||||
{
|
||||
println!("{:?},{:?},{:?},{:?}", datetime, mac, manu, decoded);
|
||||
mac = Vec::new();
|
||||
manu = Vec::new();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
let deserialized: Resume = serde_json::from_str(&json).unwrap();
|
||||
// println!("deserialized = {:?}", deserialized);
|
||||
|
||||
// Convert each publication.
|
||||
let mut items = Vec::new();
|
||||
for article in deserialized.publications {
|
||||
// Convert date.
|
||||
let date = Utc.datetime_from_str(
|
||||
&(article.releaseDate + " 00:00:00"),
|
||||
"%Y-%m-%d %H:%M:%S"
|
||||
).unwrap(); // "2018-03-20"
|
||||
// println!("{}", date);
|
||||
|
||||
/*
|
||||
<item>
|
||||
<title>Example entry</title>
|
||||
<description>Here is some text containing an interesting description.</description>
|
||||
<link>http://www.example.com/blog/post/1</link>
|
||||
<guid isPermaLink="false">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
|
||||
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
|
||||
</item>
|
||||
*/
|
||||
// Compose the item.
|
||||
let item = ItemBuilder::default()
|
||||
.title(Some(article.name))
|
||||
.description(Some(article.summary))
|
||||
.link(Some(article.website))
|
||||
.pub_date(Some(date.to_rfc2822()))
|
||||
.build()
|
||||
.unwrap();
|
||||
items.push(item);
|
||||
}
|
||||
// Compose the channel.
|
||||
let channel = ChannelBuilder::default()
|
||||
.title("lupyuen")
|
||||
.link("https://lupyuen.github.io")
|
||||
.description("IoT Techie and Educator")
|
||||
.items(items)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// Write the channel.
|
||||
let string = channel.to_string(); // convert the channel to a string
|
||||
println!("{}", string);
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue