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

  • SEARCH
  • Home
  • 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 9002267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:32:52+00:00 2026-06-16T00:32:52+00:00

I have recently written a script in python that processes a Microsoft Windows DHCP

  • 0

I have recently written a script in python that processes a Microsoft Windows DHCP server dump file and generates an XML file of the current reservations using spreadsheet XML formatting.

The script basically opens a file using the python open() command, then iterates over every line (for line in file) and looks for the key word reservedip.
If the keyword is found, the line is broken up into fields using the shlex split() command.

However, when I run this script with the default dump files of the microsoft DHCP server, I get no results. also note that I was unable to use Linux’s grep command to search in the file

I then tried to open the file in gedit and save it as a unix text file. After this was done, I got results and was able to grep within the file. This method however defeats the whole point of writing a script to automate my work.

I have been searching on google but had no luck in finding what I am looking for. I also tried to open the file in binary mode, but this was also no help.

I hope somebody can help me with this.

As per request, here is an example of what the script does (at least the looping part) and the DHCP server output:

Script

# Setup an empty dictionary to store the extracted records
records = {}

# Open dhcp dump file
f = open(dhcp.txt, "r")

# Iterate file line by line
for line in f:

  # Only use line with the word "reservedip" in it
  if "reservedip" in line:

    # Split line into fields by spaces (excluding quoted substrings)
    field = shlex.split(line)

    # Add new entry for each record using the 32bit IP address int as it's key
    records[addr_to_int(field[7])] = [field[7], field[8], field[9], field[10]]

*note: addr_to_int is a function I wrote that converts a dotted IPv4 address to an integer*

DHCP dump

Unfortunately I cannot include the real DHCP server dump due to company policy. But the lines I’m trying to get out of the file look like this:

Dhcp Server \\servername.company.local Scope 172.16.104.0 Add reservedip 172.16.104.207 003386dd00gg “hostname.company.local” “Host Description” “BOTH”

Thanks in advance,
Pascal

  • 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-06-16T00:32:53+00:00Added an answer on June 16, 2026 at 12:32 am

    Possibly the encoding of these strings in the file is not in an ASCII compatible character encoding. UTF-8 and latin should be compatible since they use exactly one byte for chars that are in ASCII. UTF-16 and UTF-32 are not compatible, they use always more than one byte per character. UTF-16 is not rare in MS files, sometimes files are even mixed.

    Possibly the dump uses 2 bytes, even for ASCII characters. Then you would have r~e~s~e~r~v~e~d~i~p in the file with ~ being some other byte (can also be ~r or even ~~ which still encodes to r.

    Just a wild guess, since you are not allowed to post the actual file and I don’t know anything about MS DHCP server dumps.

    What does

    file file.txt
    

    give you?

    What about

    file --mime-type --mime-encoding
    

    That won’t necessarily tell you the encoding if it is a “mixed” binary/strings file, but if it is plain UTF/ASCII text, it should tell you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file download script that I have written, which reads files from
I have recently written some complex ruby script that eventually fails with segfaults in
I have recently written a socket server in PHP that will be handling communication
I'm working on a Windows Mobile 6.1 app written in C#. I have recently
Problem: I have web server that was recently compromised. They targeted javascript files. They
I have a script that's written in perl, and executed as CGI. It works
I have recently written an application(vb.net) that stores and allows searching for old council
I have recently written a macro for visual studio 2010 in the macro IDE,
I have recently had a linux server compromised from bots uploading .php scripts and
I have recently been working on implementing an ajax based file uploader for my

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.