{"id":2172,"date":"2013-03-10T13:11:11","date_gmt":"2013-03-10T13:11:11","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=2172"},"modified":"2015-03-10T13:15:21","modified_gmt":"2015-03-10T13:15:21","slug":"2172","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=2172","title":{"rendered":"Forcing DHCP Renewal via Batch File using Pstools"},"content":{"rendered":"<p>The challenge was to obtain all user IP addresses in order to locate them on the local LAN (i.e. to locate their switch port by checking arp caches and mac address-table entries in the usual manner).\u00a0 Once located I needed to place them into a different vlan and then have the user reboot to obtain a new IP address.\u00a0 How could I accomplish this remotely and by &#8220;stealth&#8221;.\u00a0 <!--more--><\/p>\n<p>The answer came in an old-school batch file and the use of &#8220;pstools&#8221; on my local machine. I had a list of machine names only.\u00a0 I used pstools &#8220;psexec&#8221; to obtain their IP address using ipconfig executed on the remote machine:<\/p>\n<blockquote><p>C:\\Users\\dmatthew\\Desktop\\pstools&gt;psexec \\\\L00151309 ipconfig<\/p>\n<p>PsExec v2.11 &#8211; Execute processes remotely<br \/>\nCopyright (C) 2001-2014 Mark Russinovich<br \/>\nSysinternals &#8211; www.sysinternals.com<br \/>\n[snip]<br \/>\nEthernet adapter Local Area Connection:<\/p>\n<p>Connection-specific DNS Suffix\u00a0 . :<br \/>\nIPv4 Address. . . . . . . . . . . : 172.23.25.32<br \/>\nSubnet Mask . . . . . . . . . . . : 255.255.255.0<br \/>\nDefault Gateway . . . . . . . . . : 172.23.25.254<br \/>\n[snip]<\/p><\/blockquote>\n<p>Now I had the IP address I located the user on the network and found their switch-port.\u00a0 Before I made the change to the vlan on the port I used pstools to copy a batch file &#8220;switch-vlan.bat&#8221; to the users local machine:<\/p>\n<blockquote><p>psexec \\\\L00151309 echo f | xcopy \/f \/y &#8220;\\\\FS03\\DSTGS Shared\\Scratch\\switch-vlan.bat&#8221; \\\\L00151309\\c$<\/p><\/blockquote>\n<p>Now that the file is on the remote machine I then executed the batch file which contained a 15 second pause, during which time I made the vlan change.\u00a0 Once the vlan was changed the batch file continued and had the remote machine release and renew it&#8217;s ip address and also to flush the DNS cache.<\/p>\n<blockquote><p>psexec \\\\L00151309 c:\\switch-vlan.bat<\/p><\/blockquote>\n<p>The user is now on the new VLAN and has acquired a new IP address. Success!<\/p>\n<p>This is the contents of &#8220;switch-vlan.bat&#8221; file, which is located on a server share accessible by all users:<\/p>\n<blockquote><p>@echo off<br \/>\nrem *** Sleep for 15 seconds ***<br \/>\nping 1.1.1.1 -n 1 -w 15000 &gt; nul<br \/>\nrem *** now continue ***<br \/>\nipconfig \/release<br \/>\nipconfig \/renew<br \/>\nipconfig \/flushdns<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The challenge was to obtain all user IP addresses in order to locate them on the local LAN (i.e. to locate their switch port by checking arp caches and mac address-table entries in the usual manner).\u00a0 Once located I needed to place them into a different vlan and then have the user reboot to obtain [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2172"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2172"}],"version-history":[{"count":2,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2172\/revisions"}],"predecessor-version":[{"id":2174,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2172\/revisions\/2174"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2172"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}