Skip to content

Commit 03c39cf

Browse files
committed
support for ipv4 in extractor + better subcommands
1 parent 5cd2950 commit 03c39cf

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

bacon.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ default_job = "run"
1010
# way. Don't forget the `--color always` part or the errors won't be
1111
# properly parsed.
1212
[jobs.run]
13-
command = ["cargo", "run", "extract", "phone", "target/nice.norg", "--color", "always"]
13+
command = ["cargo", "run", "ip", "todo.norg", "--color", "always"]
1414
need_stdout = true
1515

1616
# You may define here keybindings that would be specific to

src/extract.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@ impl Extractor {
2828
.map(|i| i[0].to_string())
2929
.collect()
3030
}
31+
32+
fn ips(&self) -> Vec<String> {
33+
Regex::new(r"((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}")
34+
.unwrap()
35+
.captures_iter(&self.contents)
36+
.map(|i| i[0].to_string())
37+
.collect()
38+
}
3139
}
3240

3341
pub fn extractor(xtype: &str, filename: &str) -> String {
3442
let extract = Extractor::new(filename);
3543
let matches = match xtype {
36-
"email" | "emails" | "e" | "mails" | "mail" => extract.emails(),
37-
"phone" | "mobile" | "phones" | "numbers" => extract.phones(),
44+
"email" => extract.emails(),
45+
"phone" => extract.phones(),
46+
"ip" => extract.ips(),
3847
_ => todo!(),
3948
};
4049

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ mod tests {
8282
fn check_extractor() {
8383
assert!(extract::extractor("email", "Cargo.toml").contains("aquibjavedt007@gmail.com"));
8484
assert!(extract::extractor("phone", "todo.norg").contains("9388884586"));
85+
assert!(extract::extractor("ip", "todo.norg").contains("1.1.1.1"));
8586
}
8687
}

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ fn main() {
6868
"ascii" => general::ascii(query),
6969

7070
//Extractor
71-
"extract" => extract::extractor(query, &args[3]),
71+
"email" | "emails" | "mails" | "mail" => extract::extractor("email", query),
72+
"phone" | "phones" | "mobile" | "number" => extract::extractor("phone", query),
73+
"ipv4" | "ip" | "ips" => extract::extractor("ip", query),
7274

7375
// Analyzer
7476
// "strings" | "string" | "rb" => analyze::read_binary(query, &args[2]),

todo.norg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ version: 0.0.13
4949
- [ ] base85
5050

5151
** Extarctors (extract from string)
52-
- [x] phone, email +test strings: aquibjavedt007@gmail.com, 9388884586+
53-
- [ ] ip, mac, date formats, etc
52+
- [x] phone, email, ip +test strings: aquibjavedt007@gmail.com, 9388884586+
53+
- [ ] mac, date formats, etc +192.168.1.1 1.1.1.1 255.255.255.0+
5454
- [ ] exif metadata.
55-
- [ ] extract from binary flag format
56-
- [ ] magic bytes
55+
- [ ] extract flag format from a binary file.
56+
- [ ] magic bytes.
5757

5858
** Advanced
5959
- [ ] Advanced stuff (maybe wont do this)

0 commit comments

Comments
 (0)