Python NS Scripts

Take a script, leave a script - Like the penny tray only different

Python NS Scripts

Postby Mach5 » Tue Dec 13, 2005 9:18 am

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!
Mach5
Mini Stumbler
 
Posts: 2
Joined: Tue Nov 22, 2005 9:55 am

Postby Mach5 » Mon Apr 10, 2006 6:52 am

bump! c'mon people, no one has ANY idea?
Mach5
Mini Stumbler
 
Posts: 2
Joined: Tue Nov 22, 2005 9:55 am

Postby Dutch » Mon Apr 10, 2006 7:00 am

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
All your answers are belong to Google. SEARCH DAMMIT!
Warning. Warning.
Low C8H10N4O2 level detected. Operator halted....
User avatar
Dutch
 
Posts: 6698
Joined: Fri Mar 05, 2004 12:00 pm
Location: City of Mermaids, Denmark

Postby quhaha » Tue Oct 10, 2006 7:20 pm

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.
quhaha
Mini Stumbler
 
Posts: 5
Joined: Wed Oct 04, 2006 11:39 am

Postby Thorn » Tue Oct 10, 2006 7:55 pm

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.
Thorn
Stop the TSA now! Boycott the airlines.
Thorn
 
Posts: 10340
Joined: Sat Apr 13, 2002 3:00 am
Location: Villa Straylight

Postby quhaha » Wed Oct 11, 2006 5:32 am

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!!!!!!
quhaha
Mini Stumbler
 
Posts: 5
Joined: Wed Oct 04, 2006 11:39 am

Postby Thorn » Wed Oct 11, 2006 5:46 am

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.
Thorn
Stop the TSA now! Boycott the airlines.
Thorn
 
Posts: 10340
Joined: Sat Apr 13, 2002 3:00 am
Location: Villa Straylight

Postby quhaha » Wed Oct 11, 2006 5:54 am

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.
quhaha
Mini Stumbler
 
Posts: 5
Joined: Wed Oct 04, 2006 11:39 am

Postby Dutch » Wed Oct 11, 2006 5:57 am

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
All your answers are belong to Google. SEARCH DAMMIT!
Warning. Warning.
Low C8H10N4O2 level detected. Operator halted....
User avatar
Dutch
 
Posts: 6698
Joined: Fri Mar 05, 2004 12:00 pm
Location: City of Mermaids, Denmark

Postby Thorn » Wed Oct 11, 2006 6:13 am

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.
Thorn
Stop the TSA now! Boycott the airlines.
Thorn
 
Posts: 10340
Joined: Sat Apr 13, 2002 3:00 am
Location: Villa Straylight

Postby quhaha » Wed Oct 11, 2006 7:56 am

maybe i need to learn COM stuff. i give up. it'll be faster to learn VB
quhaha
Mini Stumbler
 
Posts: 5
Joined: Wed Oct 04, 2006 11:39 am

Postby Dutch » Wed Oct 11, 2006 8:00 am

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
All your answers are belong to Google. SEARCH DAMMIT!
Warning. Warning.
Low C8H10N4O2 level detected. Operator halted....
User avatar
Dutch
 
Posts: 6698
Joined: Fri Mar 05, 2004 12:00 pm
Location: City of Mermaids, Denmark

Postby theprez98 » Wed Oct 11, 2006 8:51 am

Mach5 wrote:bump! c'mon people, no one has ANY idea?

Just a small recommendation, we don't "bump" threads here.
[font="Courier New"]"\x74\x68\x65\x70\x72\x65\x7a\x39\x38";[/font]
User avatar
theprez98
 
Posts: 3638
Joined: Tue Jan 11, 2005 8:23 pm
Location: Maryland

Postby quhaha » Wed Oct 11, 2006 9:02 am

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).
quhaha
Mini Stumbler
 
Posts: 5
Joined: Wed Oct 04, 2006 11:39 am

Postby Dutch » Wed Oct 11, 2006 9:18 am

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
All your answers are belong to Google. SEARCH DAMMIT!
Warning. Warning.
Low C8H10N4O2 level detected. Operator halted....
User avatar
Dutch
 
Posts: 6698
Joined: Fri Mar 05, 2004 12:00 pm
Location: City of Mermaids, Denmark

Next

Return to Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

cron