Jump to content











Photo
- - - - -

Tftpd32.ini - Scripting IP address changes

tftpd32.ini ip address

  • Please log in to reply
40 replies to this topic

#1 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 11 November 2011 - 12:20 PM

Hi All;

This may be my first post, but i must admit that this forum ahs already helpded me out so much already, so a BIG thank you to start with!

My task at hand is to provide the ability to 're-image' a remote device ad-hoc, when the windows OS becomes corrupt (happens fairly often!).

I have created a Winpe3.0 boot.wim, which i have been able to inject all my NIC drivers and the Script packages so when our device does PXE boot via TFTPD32 it discovers its own IP address, maps a drive to a local computer (where the image will be stored) and loads VNC. This all works perfectly, and i am in the stage of a live trial now.


The issue i have now is that the people that will be using this tool will be doing so via a simple interface (simple DOS menu structure ATM). This DOS structure will prompt the analyst what machine they are trying to PXE boot and guide them along the way.

The final stumbling point i have got to now is changing the TFTpd32.ini file (or registry entry) to reflect the local network IP structure. This is key especially for VNC for i need to ensure the WinPE environment knows where the local default gateway is, so the analyst can VNC in a reimage (if needed). The server machine that will run the TFTpd32 on the local machine will have a local IP address, this allows me to write a script that can assertain variables to set the IPPool and Default gateway.

I saw the post reply for 'NetFanTom' here http://reboot.pro/15...__fromsearch__1 saying;

tftpd32 coded the ip number:
192.168.0.1 = 1 * 256 ^ 3 +0 * 256 ^ 2 +168 * 256 ^ 1 +192 = 16820460
255.255.255.0 = 0 * 256 ^ 3 +255 * 256 ^ 2 +255 * 256 ^ 1 +255 = 16777215


It could be my poor Math skills, but this didn't add up for me? Also i am failing to see how i would be able to script this update?


Has anyone had a simlar situation to mine? Anyone got any ideas how i can move forward?


Many thanks indeed!

#2 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 11 November 2011 - 01:20 PM

The final stumbling point i have got to now is changing the TFTpd32.ini file (or registry entry) to reflect the local network IP structure. This is key especially for VNC for i need to ensure the WinPE environment knows where the local default gateway is, so the analyst can VNC in a reimage (if needed). The server machine that will run the TFTpd32 on the local machine will have a local IP address, this allows me to write a script that can assertain variables to set the IPPool and Default gateway.


Excuse, do you want a winbuilder script that generates the TFTPD32.ini? :)
  • grrrd likes this

#3 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 11 November 2011 - 01:21 PM

That would be AMAZING please? :)

#4 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 11 November 2011 - 01:29 PM

Actaully, i might not be reading that right, i dont need the script within the PE environment, i need to be able to script this on a WinXP box. This script will be hosting the repair image, Boot Wim and TFTpd32. I have a simple Batch (with some VBS) that an analyst can run when needed?

Are we talking about the same thing?

Thanks for the reply!

#5 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 11 November 2011 - 01:44 PM

Do you want a DOS batch or VBS script that generates or changes the TFTPD32.ini? :D

#6 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 11 November 2011 - 01:45 PM

Preferably a Batch(DOS)

Thank you!

#7 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 11 November 2011 - 02:14 PM

Sorry, I'm currently in the job.

If you have a little bit time, I bring you a solution with certainty. :thumbup:

Regards
:cheers:

#8 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 11 November 2011 - 02:24 PM

That is fine with me, i have been working on this for weeks now :)

#9 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 11 November 2011 - 07:04 PM

A word of warning (IF needed) :unsure:

The issue with batch might be the limit of it's math routines, basically a batch is not accurate beyond 7FFFFFF

::========================================================

::| WARNING! Limit is 2147483647 i.e. 7FFFFFFF WARNING! |

::========================================================

So, ad example a high subnet mask, like 255.255.255.240 might be a problem, as well as a "common" 192.168.0.255.

Even a low range, like the 10.2.7.x one could exceed the precision limit easily as 10.2.7.128 is already 2.147.942.922.

In case of need the multiply.cmd:
http://reboot.pro/2986/
might be of use, though it would make more sense to use an external program capable of managing bigger numbers, an example being EVAL:
http://www.sac.sk/fi...s.php?d=16&p=27
or maybe:
http://www.codeproje...calculator.aspx
or (various programs mentioned here AND a small VBS exaple built on-the-fly):
http://groups.google...0340d597655a9d9

:cheers:
Wonko

#10 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 11 November 2011 - 10:59 PM

OKay and thanks to Wonko the Sane! :fine:

We must take VBS.

#11 madmax69

madmax69

    Member

  • Members
  • 41 posts
  •  
    United Kingdom

Posted 12 November 2011 - 02:23 AM

Sounds like an interesting project. I've already done something you might be able to use but it's not dos. It can be driven from ordinary batch files though but it's 32-bit win32 command line. It has lots of command switches.

If you intend picking up the 32 bit networking details then this may not be as easy from a 16 bit dos script anyway.

Check out TFTPLaunch which can launch and auto-configure tftpd32 from a batch file. I needed a similar gizmo and decided to write on in "C" (the maths is a bit fiddly and some of the values are stored in network-endian format) You will also run into some bugs with tftpd32 with respect to it's config file handling. I found them non resolvable within tftpd32.

http://tftplaunch.kerys.co.uk/ - use tftplaunch.exe /? for info

#12 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 12 November 2011 - 05:07 PM

We must take VBS.

FALSE - we can take the segment offset method. :jump:

But we need not take the segment offset method,
simply because
Numbers larger than 127 * 256 * 256 * 256 go into negative area over.

A generate tftpd32.ini batch:
GenTftpi.bat - Download : http://netfantom.reb...enTftpi_v05.zip

@echo off

rem goto T01

rem === version 05 ====

rem === Usage: GenTftpi [[[[ip] gate] mask] dns] ===

rem === e.g. GenTftpi ===

rem === e.g. GenTftpi 192.168.0.5 ===

rem === e.g. GenTftpi 192.168.0.5 192.168.0.254 ===

rem === e.g. GenTftpi 192.168.0.5 0.0.0.0 ===

rem === e.g. GenTftpi 192.168.0.5 192.168.0.254 255.255.255.0 192.168.0.2===

rem === try writing ===

rem === If tftpd32.ini exist tftpd32.ini will overwritten !!! ===

setlocal ENABLEDELAYEDEXPANSION

If "%1"=="/?" goto XUS

type nul>tftpd32.ini||goto :EOF

rem codedip for 255.255.255.0 is 16777215

rem codedip for 192.168.0.30 is 503359680

rem codedip for 192.168.0.2 is 33597632

rem codedip for 192.168.0.250 is -100620096

rem LocalIP is blank

rem === generate tftpd32.ini ===

rem defaults:

set _vip=192.168.0.30

set _vgate=

set _vmask=255.255.255.0

set _vdns=

If not "%1"=="" set _vip=%1

If not "%2"=="" set _vgate=%2

If not "%3"=="" set _vmask=%3

If not "%4"=="" set _vdns=%4

(

echo [DHCP]

echo Lease_NumLeases=0

echo Lease ^(minutes^)=2816

)>>tftpd32.ini

call:ipcoding %_vmask%

(

echo Mask=%codedip%

echo BootFile=/Boot/bootpxe/grldr

echo PoolSize=100

)>>tftpd32.ini

call:ipcoding %_vip%

echo IP_Pool=%codedip% >>tftpd32.ini

call:ipcoding %_vdns%

echo DNS=%codedip% >>tftpd32.ini

call:ipcoding %_vgate%

(

echo Gateway=%codedip%

echo.

echo [TFTPD32]

echo BaseDirectory=

echo TftpPort=69

echo Hide=0

echo WinSize=0

echo Negociate=1

echo PXECompatibility=0

echo DirText=0

echo ShowProgressBar=0

echo Timeout=3

echo MaxRetransmit=6

echo SecurityLevel=1

echo UnixStrings=1

echo Beep=0

echo VirtualRoot=1

echo MD5=0

echo LocalIP=

echo Services=15

echo TftpLogFile=

echo SaveSyslogFile=

echo PipeSyslogMsg=0

echo LowestUDPPort=0

echo HighestUDPPort=0

echo MulticastPort=0

echo MulticastAddress=

echo PersistantLeases=1

echo DHCP Ping=1

echo DHCP LocalIP=

echo Max Simultaneous Transfers=100

echo UseEventLog=0

echo Console Password=tftpd32

echo Support for port Option=0

)>> tftpd32.ini

goto:END

:T01

Call:ipcoding %1

Echo codedip=%codedip%

goto:END



::   -   S u b r o u t i n e s   -   ::



:ipcoding

:: Usage:  Call :ipcoding ipv4

::	e.g. call :ipcoding 192.168.0.1

:: Returns  : codedip for tftpd32.ini

SET xipv4=%1

SET xipv4=%xipv4:.= %

Call:ipcoding2 %xipv4%

if %Error% GTR 0 Set codedip=0

set xipv4=

goto:EOF

:ipcoding2

:: Usage:  Call :ipcoding2 u v w x

::	e.g. call :ipcoding2 192 168 0 1

:: Returns  : codedip for tftpd32.ini

Set codedip=

set Error=0

If "%1"=="" (Set Error=1)&(goto:EOF)

If "%2"=="" (Set Error=2)&(goto:EOF)

If "%3"=="" (Set Error=3)&(goto:EOF)

If "%4"=="" (Set Error=4)&(goto:EOF)

rem elimates pre zeros

set /a ip1=10000%1 %%10000

IF %ip1% GTR 255 SET ip1=255



set /a ip2=10000%2 %%10000

IF %ip2% GTR 255 SET ip2=255



set /a ip3=10000%3 %%10000

IF %ip3% GTR 255 SET ip3=255



set /a ip4=10000%4 %%10000

IF %ip4% GTR 255 SET ip4=255



set /a ip2=256*%ip2%

set /a ip3=256*256*%ip3%

rem if %ip4% EQU 127, than 256*256*256*%ip4% = 2,130,706,432

set /a ip4=256*256*256*%ip4%

set /a codedip=%ip1%+%ip2%+%ip3%+%ip4%

goto:EOF

:XUS

echo === Usage: GenTftpi [[[[ip] gate] mask] dns] ===

echo === e.g. GenTftpi ===

echo === e.g. GenTftpi 192.168.0.5 ===

echo === e.g. GenTftpi 192.168.0.5 192.168.0.254 ===

echo === e.g. GenTftpi 192.168.0.5 0.0.0.0 ===

echo === e.g. GenTftpi 192.168.0.5 192.168.0.254 255.255.255.0 192.168.0.2===

goto:EOF

:END

For %%a in (1 2 3 4) do set ip%%a=

For %%a in (_vmask _vip _vdns _vgate) do set %%a=

goto :EOF


Without claiming perfection.

Regards,

NetFanTom
:suda: B) :D

#13 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 12 November 2011 - 06:49 PM

Just FYI:
A snippet like this (example):

echo [DHCP]> tftpd32.ini
echo Lease_NumLeases=0 >> tftpd32.ini
echo Lease (minutes)=2816>> tftpd32.ini


Can be written as:

(
echo [DHCP]
echo Lease_NumLeases=0
echo Lease (minutes)=2816
)> tftpd32.ini


See:
http://www.robvander...levertricks.php
Search for "Group commands for redirection:" on the page.

Of course in later wites you need the >> redirection to append.

:cheers:
Wonko

#14 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 13 November 2011 - 08:46 AM

(
echo [DHCP]
echo Lease_NumLeases=0
echo Lease (minutes)=2816
)> tftpd32.ini


sorry, i get a syntax error. :)

#15 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 November 2011 - 09:30 AM

sorry, i get a syntax error. :)

Sure, my bad :( you have brackets inside brackets in this specific case.
You may want to escape them:
(

echo [DHCP]

echo Lease_NumLeases=0

echo Lease ^(minutes^)=2816

)> tftpd32.ini

:cheers:
Wonko

#16 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 13 November 2011 - 11:01 AM

Thank You! :clapping:

Version v02 is out.

:cheers:
NetFanTom

#17 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 November 2011 - 12:16 PM

May I ask what this is for? :unsure:
If exist tftpd32.ini del tftpd32.ini

If exist tftpd32.ini goto:EOF

echo.> tftpd32.ini

If not exist tftpd32.ini goto:EOF

del tftpd32.ini

I guess that you want to make sure that there is no tftp32.ini in the directory you run the batch in and that it is writable?

:cheers:
Wonko

#18 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 13 November 2011 - 01:22 PM

I guess that you want to make sure that there is no tftp32.ini in the directory you run the batch in and that it is writable?

If the tftpd32.ini exist then the file should overwritten.
if the tftpd32.ini not exist then the file should create.


:cheers:
NetFanTom

#19 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 November 2011 - 02:45 PM

If the tftpd32.ini exist then the file should overwritten.
if the tftpd32.ini not exist then the file should create.

Well, if you already know that you run in a writable media and in a writable directory and that tftp32.ini s not Read-Only, and/or Hidden/System, then this would be enough:
ECHO.>tftpd32.ini
If for any reason the write fails you can have:
ECHO.>tftpd32.ini||GOTO :EOF
or, even more elegant ;) (as it will produce an actual empty, i.e. 0 byte file):
CD.>tftpd32.ini||GOTO :EOF

:cheers:
Wonko

#20 madmax69

madmax69

    Member

  • Members
  • 41 posts
  •  
    United Kingdom

Posted 14 November 2011 - 03:19 AM

Awesome batch file! :D

I was inspired to write a small 32-bit "C" console app to do this type of math which can be used to set the environment variables directly. I like to have stuff like this in my toolkit and it didn't take too long to do (and I needed a break from PXE stuff!)

http://software.kerys.co.uk/ipcalc/ (quick cut-and-paste holding page from another app but should be enough)

ipcalc /? for info including how to set an ENV variable with the results (use /net for tftpd32 use)

#21 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 14 November 2011 - 07:46 AM

CD.> tftpd32.ini | | GOTO:. EOF

I prefer type nul> because it is understandable later. :D

ipcalc looks quite good. :thumbup:
I am assuming that you have noticed, tftpd32 calculated vice versa.
eg 192.168.0.1
normal:
192 * 256 * 256 * 256 +168 * 256 * 256 +0 * 256 +1
tftpd32:
192 +168 * 256 +0 * 256 * 256 +1 * 256 * 256 * 256

btw: Version v03 is out.

Regards,
NetFanTom
:good:

#22 NetFanTom

NetFanTom

    Frequent Member

  • .script developer
  • 117 posts
  •  
    Germany

Posted 14 November 2011 - 08:31 AM

@madmax69:

An excellent website. :clap:
Thank you very much.

May I ask you to provide an example:
Why do you need tftplaunch
and ipcalc?

Regards,
NetFanTom

#23 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 14 November 2011 - 08:36 AM

Can i just say a Massive Thank you to all replys! Really seems to be a great forum here!

I am going to put to task the above scripts now (not allowed to do such things on the weekends!) and i will let you all know.

Thank you again every so much!

#24 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 14 November 2011 - 02:43 PM

Iv have been testing this all day today and WOW it works really well!

Thank you all once again!

1 question i did have is that because i am calling this within a script, it opens it's own CMD prompt to run, but doesn't close this prompt. Due to the looping back i cant see where i need to put the 'exit' statement in so it closes itself down nicely?

#25 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 November 2011 - 02:50 PM

1 question i did have is that because i am calling this within a script, it opens it's own CMD prompt to run, but doesn't close this prompt. Due to the looping back i cant see where i need to put the 'exit' statement in so it closes itself down nicely?

You normally do not need an EXIT statement :dubbio: (which however would go here):

)>> tftpd32.ini
EXIT
goto:EOF


HOW EXACTLY are you calling the script? :unsure:

:cheers:
Wonko




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users