473,511 Members | 16,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Question

mac_string = '001485e55503' (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this ....

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.
What I do is break the string into 6 parts like this,

str01=mac_string[0:2]
str02=mac_string[2:4]
str03=mac_string[4:6]
str04=mac_string[6:8]
str05=mac_string[8:10]
str06=mac_string[10:12]

and if I use it like this

s.sendto('\xff'*6 + '\xstr01\xstr02\xstr03\xstr04\xstr05\xstr06'*16,
('192.168.1.255', 80))
I get an error
I also tried like this
s.sendto('\xff'*6 + 'mac_string'*16, ('192.168.1.255', 80))

Thiis also didnt work.
Since the MAC adddress are hexadecimal, how should I go about it here.

Please help, every help is appreciated. Thanks

Jun 28 '06 #1
7 1640
di********@gmail.com wrote:
mac_string = '001485e55503' (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this ....

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.


s.sendto('\xff'*6 + binascii.unhexlify(mac_string) *16, ('192.168.1.255', 80))

</F>

Jun 28 '06 #2

di********@gmail.com wrote:
mac_string = '001485e55503' (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this ....

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.
What I do is break the string into 6 parts like this,

str01=mac_string[0:2]
str02=mac_string[2:4]
str03=mac_string[4:6]
str04=mac_string[6:8]
str05=mac_string[8:10]
str06=mac_string[10:12]

and if I use it like this

s.sendto('\xff'*6 + '\xstr01\xstr02\xstr03\xstr04\xstr05\xstr06'*16,
('192.168.1.255', 80))
I get an error
I also tried like this
s.sendto('\xff'*6 + 'mac_string'*16, ('192.168.1.255', 80))

Thiis also didnt work.
Since the MAC adddress are hexadecimal, how should I go about it here.

Please help, every help is appreciated. Thanks


See http://docs.python.org/lib/typesseq-strings.html

You probably want:

s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
sttr04, str05, str06))*16, ('192.168.1.255', 80))

Iain

Jun 28 '06 #3
Many Thanks!! It worked like a charm.

Fredrik Lundh wrote:
di********@gmail.com wrote:
mac_string = '001485e55503' (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this ....

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.


s.sendto('\xff'*6 + binascii.unhexlify(mac_string) *16, ('192.168.1.255', 80))

</F>


Jun 28 '06 #4
I will try this one too...thanks for your response.
Iain King wrote:
di********@gmail.com wrote:
mac_string = '001485e55503' (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this ....

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.
What I do is break the string into 6 parts like this,

str01=mac_string[0:2]
str02=mac_string[2:4]
str03=mac_string[4:6]
str04=mac_string[6:8]
str05=mac_string[8:10]
str06=mac_string[10:12]

and if I use it like this

s.sendto('\xff'*6 + '\xstr01\xstr02\xstr03\xstr04\xstr05\xstr06'*16,
('192.168.1.255', 80))
I get an error
I also tried like this
s.sendto('\xff'*6 + 'mac_string'*16, ('192.168.1.255', 80))

Thiis also didnt work.
Since the MAC adddress are hexadecimal, how should I go about it here.

Please help, every help is appreciated. Thanks


See http://docs.python.org/lib/typesseq-strings.html

You probably want:

s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
sttr04, str05, str06))*16, ('192.168.1.255', 80))

Iain


Jun 28 '06 #5
di********@gmail.com wrote:
mac_string = '001485e55503' (This is the mac address of a computer.)
Since the MAC adddress are hexadecimal, how should I go about it here.

Please help, every help is appreciated. Thanks


I could not quite understand what you are trying to achieve, but
it appears that you want to convert a character strings of hexadecimal
characters into a byte string with the same bytes. I recommend this:

py> import binascii
py> binascii.a2b_hex("001485e55503")
'\x00\x14\x85\xe5U\x03'

Of course, if the string is fixed, you could just as well use the
result string (i.e. '\x00\x14\x85\xe5U\x03') directly.

Regards,
Martin
Jun 28 '06 #6
"Iain King" <ia******@gmail.com> wrote:

You probably want:

s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
sttr04, str05, str06))*16, ('192.168.1.255', 80))


You probably should TRY suggestions before you post them. That will get an
"invalid \x escape". \x must be followed by exactly two hex digits. You
can't build up an escape sequence like this.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 30 '06 #7

Tim Roberts wrote:
"Iain King" <ia******@gmail.com> wrote:

You probably want:

s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
sttr04, str05, str06))*16, ('192.168.1.255', 80))


You probably should TRY suggestions before you post them. That will get an
"invalid \x escape". \x must be followed by exactly two hex digits. You
can't build up an escape sequence like this.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.


You're right. I'd foolishly assumed that \x was just another character
code, like \t or \n. Apologies.

Iain

Jun 30 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1451
by: sparks | last post by:
I know this is a stupid question but I can't find the answer. Please tell me where to find reference to this so I can print it out and staple it to my head.. dim I as integer dim missedstr as...
5
3013
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
5
12447
by: Dave | last post by:
I'm receiving info from a com port into a string. I gradually process the string which constantly shortens it. The question is how long can a string be before I need to write some info to disk...
32
14762
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
8539
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
11
17624
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
53
4021
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
6
2194
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
39
2867
by: sucaba.r | last post by:
I don't know if this is a unique problem, or I'm going about it the wrong way. I currently connect to one of our SQL servers via a priviliged account (by using RUNAS). Works with no problem. I...
7
7798
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.