Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Matus Kubis
wifi-stats
Commits
2a993ec5
Commit
2a993ec5
authored
Mar 21, 2018
by
Matus Kubis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add script
parent
76b6b6ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
__main__.py
__main__.py
+95
-0
No files found.
__main__.py
0 → 100644
View file @
2a993ec5
import
logging
import
argparse
import
os
from
pysnmp.hlapi
import
*
from
cassandra.cluster
import
Cluster
def
setup_logging
():
logging
.
basicConfig
(
level
=
'INFO'
)
logging
.
info
(
'Lgging started'
)
def
mib_walk
(
ip
,
mib
):
data
=
{}
for
(
errorIndication
,
errorStatus
,
errorIndex
,
varBinds
)
in
nextCmd
(
SnmpEngine
(),
CommunityData
(
'public'
),
UdpTransportTarget
((
ip
,
161
)),
ContextData
(),
ObjectType
(
ObjectIdentity
(
mib
))):
if
errorIndication
:
print
(
errorIndication
)
break
elif
errorStatus
:
print
(
'%s at %s'
%
(
errorStatus
.
prettyPrint
(),
errorIndex
and
varBinds
[
int
(
errorIndex
)
-
1
][
0
]
or
'?'
))
break
else
:
done
=
False
for
varBind
in
varBinds
:
id
=
str
(
varBind
[
0
])
done
=
not
str
(
varBind
[
0
]).
startswith
(
mib
)
if
done
:
break
data
[
id
]
=
varBind
[
1
].
prettyPrint
()
if
done
:
break
return
data
def
main
():
setup_logging
()
mib
=
'1.3.6.1.4.1.14988.1.1.1.5.1.11'
ip
=
'147.175.186.234'
data
=
mib_walk
(
ip
,
mib
)
for
k
in
data
:
idsplit
=
k
.
split
(
'.'
)
cat
=
'.'
.
join
(
idsplit
[:
13
])
usr
=
'.'
.
join
(
idsplit
[
13
:])
print
(
cat
,
usr
,
data
[
k
])
print
(
"Cassandra thing"
)
cluster
=
Cluster
()
session
=
cluster
.
connect
()
session
.
execute
(
'CREATE KEYSPACE IF NOT EXISTS wifi WITH REPLICATION = {
\'
class
\'
:
\'
SimpleStrategy
\'
,
\'
replication_factor
\'
: 1 }'
)
session
.
execute
(
'USE wifi'
)
# session.execute('DROP TABLE devices')
session
.
execute
(
'''CREATE TABLE IF NOT EXISTS devices (
mac text,
time timestamp,
cap text,
strength int,
txbytes bigint,
rxbytes bigint,
txpackets bigint,
rxpackets bigint,
txrate text,
rxrate text,
assoctime int,
PRIMARY KEY (mac, time)
) WITH CLUSTERING ORDER BY (time DESC)'''
)
session
.
execute
(
'INSERT INTO devices (mac, time) VALUES (
\'
aa:bb:cc:dd:ee:ff
\'
,
\'
2018-01-01 11:00:02
\'
)'
)
dat
=
session
.
execute
(
'SELECT * FROM devices'
)
for
d
in
dat
:
print
(
d
)
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment