Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:27+00:00 2026-05-26T04:21:27+00:00

I am trying to convert a PHP code to python. All values are send

  • 0

I am trying to convert a PHP code to python.

All values are send in network byte order (big endian).

Basically, the REQUEST in protocol specification is

enter image description here

and response is

enter image description here

Corresponding PHP Code (corresponding DOC) is:

$transaction_id = mt_rand(0,65535);
$current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
$fp = fsockopen($tracker, $port, $errno, $errstr);
$packet = $current_connid . pack("N", 0) . pack("N", $transaction_id);
fwrite($fp,$packet);

I am trying to find the corresponding code (for doc) in python:

transaction_id = random.randrange(1,65535)
packet = "\x00\x00\x04\x17\x27\x10\x19\x80"
packet = packet + struct.pack("i", 0) + struct.pack("i", transaction_id)
clisocket =  socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
clisocket.sendto(packet, ("tracker.istole.it", 80))

In the response, I should get the same transaction_id I sent in the request which I am not getting. So, my guess is, I am not packing using correct format.

Also, the python documentation is not as clear as that of PHP. The protocol specifies to use Big Endian format & PHP doc clearly states which are the ones for Big-Endian.

Sadly, I could not comprehend which format to use in python. Please help me in choosing the corrent format.

EDIT:
Not getting any responses, so I would say more.

import struct
import socket
import random

clisocket =  socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
packet = "\x00\x00\x04\x17\x27\x10\x19\x80"
transaction_id = random.randrange(1,65535)
print transaction_id
packet = packet+struct.pack(">i", 0)
packet = packet+struct.pack(">i", transaction_id)

clisocket.sendto(packet, ("tracker.istole.it", 80))
res = clisocket.recv(16)

print struct.unpack(">i", res[12:16])

According to protocol specification, I should be returned same INTEGER.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:21:28+00:00Added an answer on May 26, 2026 at 4:21 am

    The php pack function format N means unsigned 32-bit big-endian integer.
    The corresponding Python struct.pack format is >L.

    The images you posted for the protocol show the connection_id should be 64-bit (unsigned) integer: Python struct.pack format Q.

    So:

    clisocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    connection_id=0x41727101980
    action=0
    # transaction_id = random.randrange(1,65535)
    transaction_id = 12345    
    print(transaction_id)
    # 12345
    
    packet=struct.pack(">QLL",connection_id,action,transaction_id)
    print(repr(packet))
    # "\x00\x00\x04\x17'\x10\x19\x80\x00\x00\x00\x00\x00\x0009"
    
    clisocket.sendto(packet, ("tracker.istole.it", 80))
    res = clisocket.recv(16)
    action,transaction_id,connection_id=struct.unpack(">LLQ",res)
    print(action)
    # 0
    print(transaction_id)
    # 12345 
    print(connection_id)
    # 2540598739861590271
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm trying to convert the PHP Code example for an AWIS request found
I am trying to convert the following python code to a PHP code. Can
I'm trying to convert some php code into python and am using curl. I've
Hey gang, I'm trying to convert a legacy php script over to python and
I'm trying to convert this piece of code from PHP to C#. It's part
I'm pretty new to Perl and trying to convert some PHP code to Perl.
I'm trying to convert this adaptive bayesian rating formula into PHP code: see here
I'm trying to convert my procedural code to oop. <?php $dbc = get_dbc(); $info
Trying to convert this c code into MIPS and run it in SPIM. int
I'm trying to convert old QuickTime framework code to the 64-bit Cocoa-based QTKit on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.