Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created January 17, 2019 15:16
Show Gist options
  • Save muxueqz/60bf26e79e81161b7da8e6867f35cd85 to your computer and use it in GitHub Desktop.
Save muxueqz/60bf26e79e81161b7da8e6867f35cd85 to your computer and use it in GitHub Desktop.
import strutils
import osproc
let outp = execProcess("iwlist wlan0 scan | grep ESSID ")
var wifi_name = outp.split('"')[1]
proc ascii2utf8(s: string): string =
var u_strs: seq[int]
# for i in s.split("\\x"):
# if i.len > 1:
# var u_int = join(["0x", i])
# u_strs.add u_int.parseHexInt
# var u_result: seq[string]
# for i in 0..u_strs.len/%3 - 1:
# var u_r = [u_strs[i*3].chr, u_strs[i*3+1].chr, u_strs[i*3+2].chr].join
# u_result.add u_r
var u_result: seq[string]
echo s.len
var str_step = 3 * 4
var n_s = s.replace("\\x", "0x")
for i in 0..s.len/%str_step - 1:
echo i
var u_r = [
n_s[i*str_step..i*str_step+3].parseHexInt.char,
n_s[(i*str_step)+1*4..(i*str_step)+1*4+3].parseHexInt.char,
n_s[(i*str_step)+2*4..(i*str_step)+2*4+3].parseHexInt.char,
].join
u_result.add u_r
result = u_result.join
echo wifi_name
echo ascii2utf8(wifi_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment