Page 1 of 2

Python NS Scripts

PostPosted: Tue Dec 13, 2005 9:18 am
by Mach5
Has anyone sucessfully coded a python script for netstumbler? I've made some attempts at it using the VB master script as an example, but py and vb aren't imported in the same way. I see that NS uses some python library called axscript (in the win32com lib), but there is little documentation on it. Besides hacking through code (as I'm doing now), I'm hoping someone here has an example or at least a hint :). Thanks in advance!

PostPosted: Mon Apr 10, 2006 6:52 am
by Mach5
bump! c'mon people, no one has ANY idea?

PostPosted: Mon Apr 10, 2006 7:00 am
by Dutch
Mach5 wrote:bump! c'mon people, no one has ANY idea?

NS does not have any embedded scripting engine. Any scripts executed by NS needs to have a scripting engine installed in Windows. If there's no Python scripting engine available, you are SOL.
What NS does is start the scripting engine with the script specified and expose some variables and functions that the scripting engine can call to get data.
Python AFAIK is not a scripting engine, but an interpreted programming language.

Dutch

PostPosted: Tue Oct 10, 2006 7:20 pm
by quhaha
ok I installed ActivePython from ActiveState. NetStumbler now let me choose a python file as external script.

My python file looks like:
Code: Select all
PlaySound("C:\Program Files\Network Stumbler\ns-signal-1.wav")


Of course it says:
Code: Select all
---------------------------
NetStumbler
---------------------------
An error was reported in your script.



Python ActiveX Scripting Engine

Traceback (most recent call last):
  File "<Script Block >", line 1, in ?
    PlaySound("C:\Program Files\Network Stumbler\ns-signal-1.wav")
NameError: name 'PlaySound' is not defined


Line:1 Char: 0

Exception occurred.


because i didn't import anything that defines PlaySound...
So, which library defines PlaySound??

Thanks.

PostPosted: Tue Oct 10, 2006 7:55 pm
by Thorn
quhaha wrote:ok I installed ActivePython from ActiveState. NetStumbler now let me choose a python file as external script.

My python file looks like:
Code: Select all
PlaySound("C:\Program Files\Network Stumbler\ns-signal-1.wav")


Of course it says:
Code: Select all
---------------------------
NetStumbler
---------------------------
An error was reported in your script.



Python ActiveX Scripting Engine

Traceback (most recent call last):
  File "<Script Block >", line 1, in ?
    PlaySound("C:\Program Files\Network Stumbler\ns-signal-1.wav")
NameError: name 'PlaySound' is not defined


Line:1 Char: 0

Exception occurred.


because i didn't import anything that defines PlaySound...
So, which library defines PlaySound??

Thanks.

It's the "winsound" library.

Google "Python playsound" and "Python playsound winsound", and you should find plenty of references.

PostPosted: Wed Oct 11, 2006 5:32 am
by quhaha
Thorn wrote:It's the "winsound" library.

Google "Python playsound" and "Python playsound winsound", and you hsould find plenty of references.

Thanks!!!

Now, I can do stuff like:
Code: Select all
import winsound
import easygui

easygui.msgbox('lol')
winsound.PlaySound("ns-signal-1.wav", winsound.SND_FILENAME)

easygui is from : http://ferg.org/easygui/ (simple Tkinter routines)

If I run above, it displays a message box and when I close it, it plays sound (easygui.msgbox probably has a loop).

So far so good.

Now, I want to try OnScalResult:
First, using JScript:
Code: Select all
function OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen) {
   PlaySound("ns-signal-1.wav")]
If I run above, it plays periodic sound, whenever scan is done.

Now, onto Python:
[code]
import winsound

def OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen):
    winsound.PlaySound("ns-signal-1.wav", winsound.SND_FILENAME)

[/code]
Now, the script doesn't even run (when I click Apply, it shows Not Running).

Do I have to put OnScanResult to some specific module??

I don't know why JScript version works but not Python version...
Ok, to make Python version really identical to JScript version, I did:
[code]
import winsound
def PlaySound(name):
    winsound.PlaySound(name, winsound.SND_FILENAME)

def OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen):
    PlaySound("ns-signal-1.wav")



Still, NetStumbler doesn't seem to call OnScanResult...
Help.
Thanks.


-edit
Better yet, if there is a documentation that describes how netstumbler calls those functions..etc will be awesome!!!!!!

PostPosted: Wed Oct 11, 2006 5:46 am
by Thorn
quhaha wrote:Thanks!!!

...

easygui is from : http://ferg.org/easygui/ (simple Tkinter routines)
...
Help.
Thanks.
You're welcome, but I can't help anymore on this. I don't know Python]if you know what you are doing[/I]. However, if you don't know or understand the underlying language itself, a GUI will just complicate the subject. Real programmers use the command line.

Maybe someone else can help, but it would seem that you really just need to read a book or three on Python, and learn to use some search tools.

PostPosted: Wed Oct 11, 2006 5:54 am
by quhaha
GUI is not really the point... I just wanted to know how come NetStumbler calls JScript function OnResultScan..but not Python's..I think Python's OnScanResult is valid function...it runs on Python Interpreter.

PostPosted: Wed Oct 11, 2006 5:57 am
by Dutch
quhaha wrote:GUI is not really the point... I just wanted to know how come NetStumbler calls JScript function OnResultScan..but not Python's..I think Python's OnScanResult is valid function...it runs on Python Interpreter.

Netstumbler doesn't call any functions.
It's the script that calls the functions that Netstumbler exposes to the Scripting engines.
You need to read up on how to call external functions from what ever scripting language you choose to use.

See this for further information.

Dutch

PostPosted: Wed Oct 11, 2006 6:13 am
by Thorn
quhaha wrote:
-edit
Better yet, if there is a documentation that describes how netstumbler calls those functions..etc will be awesome!!!!!!

Yes, it's a sticky for a reason.

Official NetStumbler Scripting Guide

or http://www.stumbler.net/scripting.html

quhaha wrote:GUI is not really the point... I just wanted to know how come NetStumbler calls JScript function OnResultScan..but not Python's..I think Python's OnScanResult is valid function...it runs on Python Interpreter.
You're missing the point about not fully understanding the lanquage. A GUI will add more things you don't understand. You need to have a basic understanding of the language before you start getting fancy with it, that's all. It's just a simple matter of learning to walk before learning to run.

PostPosted: Wed Oct 11, 2006 7:56 am
by quhaha
maybe i need to learn COM stuff. i give up. it'll be faster to learn VB

PostPosted: Wed Oct 11, 2006 8:00 am
by Dutch
quhaha wrote:maybe i need to learn COM stuff. i give up. it'll be faster to learn VB

If you want to hang around these forums you need to learn to write like an adult. There's a reason why capital letters, punctuation and the shift key exists on your keyboard. Read the Welcome Desk section, and pay particular note to the thread regarding the usage of proper written english around here.

Dutch

PostPosted: Wed Oct 11, 2006 8:51 am
by theprez98
Mach5 wrote:bump! c'mon people, no one has ANY idea?

Just a small recommendation, we don't "bump" threads here.

PostPosted: Wed Oct 11, 2006 9:02 am
by quhaha
Code: Select all
#!C:/Perl/bin/perl.exe -w

sub OnScanResult {
   my($sid,$mac,$flags,$signal,$noise,$ls) = @_;
   PlaySound('ns-signal-1.wav');
}

That one works too.
I just noticed that NetStumbler supports Python.AXScript and PerlScript, not Python and Perl.

I think win32com.axscript module isn't implemented yet (Not sure about this).
Probably that explains why PerlScript already has access to PlaySound but Python.AXScript doesn't (I used winsound.PlaySound).

PostPosted: Wed Oct 11, 2006 9:18 am
by Dutch
quhaha wrote:[code]
#!C:/Perl/bin/perl.exe -w

sub OnScanResult {
my($sid,$mac,$flags,$signal,$noise,$ls) = @_]
That one works too.
I just noticed that NetStumbler supports Python.AXScript and PerlScript, not Python and Perl.

I think win32com.axscript module isn't implemented yet (Not sure about this).
Probably that explains why PerlScript already has access to PlaySound but Python.AXScript doesn't (I used winsound.PlaySound).


So you are saying that the following, which I posted here way back in April 2006 : "Python AFAIK is not a scripting engine, but an interpreted programming language." is actually true ? Amazing, isn't it ?? Who would have thought that I did any kind of research before replying to a post here...

:rolleyes:

Dutch